You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Gary Gregory <ga...@gmail.com> on 2018/02/24 04:13:06 UTC

Core 4.x and custom HttpRequestFactory

Hi All,

In my proxy, I use:

DefaultHttpServerIODispatch.create(serviceHandler, serverSslContext,
serverConnectionConfig)

In order to support HTTP DELETE with a message body (I know, I know), I've
created a custom HttpRequestFactory implementation.

So I want this to kick in so that by the time my
custom org.apache.http.nio.protocol.HttpAsyncRequestProducer.generateRequest()
 called, the request is the BasicHttpEntityEnclosingRequest I created in my
HttpRequestFactory.

A HttpRequestFactory lives in a NHttpMessageParserFactory<HttpRequest>.

Would it be acceptable to add support for HttpRequestFactory and/or
NHttpMessageParserFactory to ConnectionConfig?

Gary

Re: Core 4.x and custom HttpRequestFactory

Posted by Gary Gregory <ga...@gmail.com>.
Done. Tracked with https://issues.apache.org/jira/browse/HTTPCORE-515

Gary

On Mon, Feb 26, 2018 at 10:37 AM, Gary Gregory <ga...@gmail.com>
wrote:

>
>
> On Mon, Feb 26, 2018 at 4:12 AM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
>
>> On Sun, 2018-02-25 at 13:36 -0700, Gary Gregory wrote:
>> > On Sat, Feb 24, 2018 at 8:45 AM, Gary Gregory <garydgregory@gmail.com
>> > >
>> >
>> ...
>>
>>
>> > My code now uses this method:
>> >
>> >     private DefaultHttpServerIODispatch<ProxyServiceHandler>
>> > createHttpServerIODispatch(final SSLContext sslContext, final
>> > ConnectionConfig serverConnectionConfig) {
>> >         NHttpMessageParserFactory<HttpRequest>
>> > httpRequestParserFactory =
>> > new DefaultHttpRequestParserFactory(null,
>> > CompleteHttpRequestFactory.INSTANCE);
>> >         // @formatter:off
>> >         return sslContext == null
>> >                 ? new DefaultHttpServerIODispatch<>(serviceHandler,
>> >                         new DefaultNHttpServerConnectionFactory(null,
>> > httpRequestParserFactory, null, serverConnectionConfig))
>> >                 : new DefaultHttpServerIODispatch<>(serviceHandler,
>> >                         new
>> > SSLNHttpServerConnectionFactory(sslContext,
>> > null, httpRequestParserFactory, null, serverConnectionConfig));
>> >         // @formatter:om
>> >     }
>> >
>> > where  CompleteHttpRequestFactory is a custom class.
>> >
>> > This is done instead of calling
>> > DefaultHttpServerIODispatch.create(serviceHandler,
>> > serverSslContext, serverConnectionConfig)
>> >
>> > Can you see augmenting HC to make this less convoluted?
>> >
>> > Gary
>> >
>>
>> Hi Gary
>>
>> You have already added a number of convenience #create methods. Why do
>> not you add a static #create method that takes HttpRequestFactory as a
>> parameter?
>>
>
> Sure, I can do that. I am not crazy about repeating the pattern
> "sslContext == null ? ... : ..." like we have in the static method I
> initially used; which is why I wanted to push down the parser factory into
> ConnectionConfig. But I do see your point: a HttpRequestFactory and
> HttpRequestParserFactory are not part of configuring a connection.
>
> Gary
>
>
>> Oleg
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>
>

Re: Core 4.x and custom HttpRequestFactory

Posted by Gary Gregory <ga...@gmail.com>.
On Mon, Feb 26, 2018 at 4:12 AM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Sun, 2018-02-25 at 13:36 -0700, Gary Gregory wrote:
> > On Sat, Feb 24, 2018 at 8:45 AM, Gary Gregory <garydgregory@gmail.com
> > >
> >
> ...
>
>
> > My code now uses this method:
> >
> >     private DefaultHttpServerIODispatch<ProxyServiceHandler>
> > createHttpServerIODispatch(final SSLContext sslContext, final
> > ConnectionConfig serverConnectionConfig) {
> >         NHttpMessageParserFactory<HttpRequest>
> > httpRequestParserFactory =
> > new DefaultHttpRequestParserFactory(null,
> > CompleteHttpRequestFactory.INSTANCE);
> >         // @formatter:off
> >         return sslContext == null
> >                 ? new DefaultHttpServerIODispatch<>(serviceHandler,
> >                         new DefaultNHttpServerConnectionFactory(null,
> > httpRequestParserFactory, null, serverConnectionConfig))
> >                 : new DefaultHttpServerIODispatch<>(serviceHandler,
> >                         new
> > SSLNHttpServerConnectionFactory(sslContext,
> > null, httpRequestParserFactory, null, serverConnectionConfig));
> >         // @formatter:om
> >     }
> >
> > where  CompleteHttpRequestFactory is a custom class.
> >
> > This is done instead of calling
> > DefaultHttpServerIODispatch.create(serviceHandler,
> > serverSslContext, serverConnectionConfig)
> >
> > Can you see augmenting HC to make this less convoluted?
> >
> > Gary
> >
>
> Hi Gary
>
> You have already added a number of convenience #create methods. Why do
> not you add a static #create method that takes HttpRequestFactory as a
> parameter?
>

Sure, I can do that. I am not crazy about repeating the pattern "sslContext
== null ? ... : ..." like we have in the static method I initially used;
which is why I wanted to push down the parser factory into
ConnectionConfig. But I do see your point: a HttpRequestFactory and
HttpRequestParserFactory are not part of configuring a connection.

Gary


> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

Re: Core 4.x and custom HttpRequestFactory

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Sun, 2018-02-25 at 13:36 -0700, Gary Gregory wrote:
> On Sat, Feb 24, 2018 at 8:45 AM, Gary Gregory <garydgregory@gmail.com
> >
> 
...


> My code now uses this method:
> 
>     private DefaultHttpServerIODispatch<ProxyServiceHandler>
> createHttpServerIODispatch(final SSLContext sslContext, final
> ConnectionConfig serverConnectionConfig) {
>         NHttpMessageParserFactory<HttpRequest>
> httpRequestParserFactory =
> new DefaultHttpRequestParserFactory(null,
> CompleteHttpRequestFactory.INSTANCE);
>         // @formatter:off
>         return sslContext == null
>                 ? new DefaultHttpServerIODispatch<>(serviceHandler,
>                         new DefaultNHttpServerConnectionFactory(null,
> httpRequestParserFactory, null, serverConnectionConfig))
>                 : new DefaultHttpServerIODispatch<>(serviceHandler,
>                         new
> SSLNHttpServerConnectionFactory(sslContext,
> null, httpRequestParserFactory, null, serverConnectionConfig));
>         // @formatter:om
>     }
> 
> where  CompleteHttpRequestFactory is a custom class.
> 
> This is done instead of calling
> DefaultHttpServerIODispatch.create(serviceHandler,
> serverSslContext, serverConnectionConfig)
> 
> Can you see augmenting HC to make this less convoluted?
> 
> Gary
> 

Hi Gary

You have already added a number of convenience #create methods. Why do
not you add a static #create method that takes HttpRequestFactory as a
parameter?

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Re: Core 4.x and custom HttpRequestFactory

Posted by Gary Gregory <ga...@gmail.com>.
On Sat, Feb 24, 2018 at 8:45 AM, Gary Gregory <ga...@gmail.com>
wrote:

>
>
> On Sat, Feb 24, 2018 at 3:52 AM, Oleg Kalnichevski <ol...@apache.org>
> wrote:
>
>> On Fri, 2018-02-23 at 21:13 -0700, Gary Gregory wrote:
>> > Hi All,
>> >
>> > In my proxy, I use:
>> >
>> > DefaultHttpServerIODispatch.create(serviceHandler, serverSslContext,
>> > serverConnectionConfig)
>> >
>> > In order to support HTTP DELETE with a message body (I know, I know),
>> > I've
>> > created a custom HttpRequestFactory implementation.
>> >
>> > So I want this to kick in so that by the time my
>> > custom
>> > org.apache.http.nio.protocol.HttpAsyncRequestProducer.generateRequest
>> > ()
>> >  called, the request is the BasicHttpEntityEnclosingRequest I created
>> > in my
>> > HttpRequestFactory.
>> >
>> > A HttpRequestFactory lives in a
>> > NHttpMessageParserFactory<HttpRequest>.
>> >
>> > Would it be acceptable to add support for HttpRequestFactory and/or
>> > NHttpMessageParserFactory to ConnectionConfig?
>> >
>> > Gary
>>
>> Why would you want to add an HTTP protocol level interface to a class
>> that represents transport parameters?  Would there be any benefits of
>> mixing completely unrelated things?
>>
>
> From a simple point of view -- even though there is nothing simple about
> my proxy -- I have a factory method with one parameter being a "config"
> object, so I am thinking "Hey, this looks like a nice place to hang this
> object which can be picked up when this whole tree of objects gets
> constructed."
>
> I will study the code some more...
>

My code now uses this method:

    private DefaultHttpServerIODispatch<ProxyServiceHandler>
createHttpServerIODispatch(final SSLContext sslContext, final
ConnectionConfig serverConnectionConfig) {
        NHttpMessageParserFactory<HttpRequest> httpRequestParserFactory =
new DefaultHttpRequestParserFactory(null,
CompleteHttpRequestFactory.INSTANCE);
        // @formatter:off
        return sslContext == null
                ? new DefaultHttpServerIODispatch<>(serviceHandler,
                        new DefaultNHttpServerConnectionFactory(null,
httpRequestParserFactory, null, serverConnectionConfig))
                : new DefaultHttpServerIODispatch<>(serviceHandler,
                        new SSLNHttpServerConnectionFactory(sslContext,
null, httpRequestParserFactory, null, serverConnectionConfig));
        // @formatter:om
    }

where  CompleteHttpRequestFactory is a custom class.

This is done instead of calling
DefaultHttpServerIODispatch.create(serviceHandler,
serverSslContext, serverConnectionConfig)

Can you see augmenting HC to make this less convoluted?

Gary



>
> Gary
>
>
>>
>> Oleg
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
>> For additional commands, e-mail: dev-help@hc.apache.org
>>
>>
>

Re: Core 4.x and custom HttpRequestFactory

Posted by Gary Gregory <ga...@gmail.com>.
On Sat, Feb 24, 2018 at 3:52 AM, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Fri, 2018-02-23 at 21:13 -0700, Gary Gregory wrote:
> > Hi All,
> >
> > In my proxy, I use:
> >
> > DefaultHttpServerIODispatch.create(serviceHandler, serverSslContext,
> > serverConnectionConfig)
> >
> > In order to support HTTP DELETE with a message body (I know, I know),
> > I've
> > created a custom HttpRequestFactory implementation.
> >
> > So I want this to kick in so that by the time my
> > custom
> > org.apache.http.nio.protocol.HttpAsyncRequestProducer.generateRequest
> > ()
> >  called, the request is the BasicHttpEntityEnclosingRequest I created
> > in my
> > HttpRequestFactory.
> >
> > A HttpRequestFactory lives in a
> > NHttpMessageParserFactory<HttpRequest>.
> >
> > Would it be acceptable to add support for HttpRequestFactory and/or
> > NHttpMessageParserFactory to ConnectionConfig?
> >
> > Gary
>
> Why would you want to add an HTTP protocol level interface to a class
> that represents transport parameters?  Would there be any benefits of
> mixing completely unrelated things?
>

From a simple point of view -- even though there is nothing simple about my
proxy -- I have a factory method with one parameter being a "config"
object, so I am thinking "Hey, this looks like a nice place to hang this
object which can be picked up when this whole tree of objects gets
constructed."

I will study the code some more...

Gary


>
> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

Re: Core 4.x and custom HttpRequestFactory

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2018-02-23 at 21:13 -0700, Gary Gregory wrote:
> Hi All,
> 
> In my proxy, I use:
> 
> DefaultHttpServerIODispatch.create(serviceHandler, serverSslContext,
> serverConnectionConfig)
> 
> In order to support HTTP DELETE with a message body (I know, I know),
> I've
> created a custom HttpRequestFactory implementation.
> 
> So I want this to kick in so that by the time my
> custom
> org.apache.http.nio.protocol.HttpAsyncRequestProducer.generateRequest
> ()
>  called, the request is the BasicHttpEntityEnclosingRequest I created
> in my
> HttpRequestFactory.
> 
> A HttpRequestFactory lives in a
> NHttpMessageParserFactory<HttpRequest>.
> 
> Would it be acceptable to add support for HttpRequestFactory and/or
> NHttpMessageParserFactory to ConnectionConfig?
> 
> Gary

Why would you want to add an HTTP protocol level interface to a class
that represents transport parameters?  Would there be any benefits of
mixing completely unrelated things? 

Oleg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org