You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by "Francisco A. Lozano" <fl...@gmail.com> on 2022/10/28 15:28:30 UTC

HttpCoreContext.HTTP_TARGET_HOST equivalent in hc 5

Hi,

I'm trying to port a tweaked ConnectionKeepAliveStrategy which applies a
custom behaviour depending on the target host.

With 4.5.x I followed the example in:
https://hc.apache.org/httpcomponents-client-4.5.x/current/tutorial/html/connmgmt.html

and obtained the target host with

    HttpHost target = (HttpHost)
context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);

but this constant is not available anymore in the HttpCoreContext.

What is the right way to obtain the target host from the HttpContext when
moving to http client 5? I was looking at CONNECTION_ENDPOINT and the
remoteAddress of EndpointDetails, but it's not equivalent to a target
hostname.

Francisco A. Lozano

Re: HttpCoreContext.HTTP_TARGET_HOST equivalent in hc 5

Posted by "Francisco A. Lozano" <fl...@gmail.com>.
Ah, nice! given the request is expected to be in the context:

((HttpRequest)
context.getAttribute(HttpCoreContext.HTTP_REQUEST)).getAuthority().getHostName();

Thanks a lot!

Francisco A. Lozano


El sáb, 29 oct 2022 a las 10:21, Oleg Kalnichevski (<ol...@apache.org>)
escribió:
>
> On Fri, 2022-10-28 at 17:28 +0200, Francisco A. Lozano wrote:
> > Hi,
> >
> > I'm trying to port a tweaked ConnectionKeepAliveStrategy which
> > applies a
> > custom behaviour depending on the target host.
> >
> > With 4.5.x I followed the example in:
> >
https://hc.apache.org/httpcomponents-client-4.5.x/current/tutorial/html/connmgmt.html
> >
> > and obtained the target host with
> >
> >     HttpHost target = (HttpHost)
> > context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
> >
> > but this constant is not available anymore in the HttpCoreContext.
> >
> > What is the right way to obtain the target host from the HttpContext
> > when
> > moving to http client 5? I was looking at CONNECTION_ENDPOINT and the
> > remoteAddress of EndpointDetails, but it's not equivalent to a target
> > hostname.
> >
> > Francisco A. Lozano
>
> In 5.x one can get those details directly from the request object. See
> HttpRequest#getScheme and HttpRequest#getAuthority.
>
> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org

Re: HttpCoreContext.HTTP_TARGET_HOST equivalent in hc 5

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2022-10-28 at 17:28 +0200, Francisco A. Lozano wrote:
> Hi,
> 
> I'm trying to port a tweaked ConnectionKeepAliveStrategy which
> applies a
> custom behaviour depending on the target host.
> 
> With 4.5.x I followed the example in:
> https://hc.apache.org/httpcomponents-client-4.5.x/current/tutorial/html/connmgmt.html
> 
> and obtained the target host with
> 
>     HttpHost target = (HttpHost)
> context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
> 
> but this constant is not available anymore in the HttpCoreContext.
> 
> What is the right way to obtain the target host from the HttpContext
> when
> moving to http client 5? I was looking at CONNECTION_ENDPOINT and the
> remoteAddress of EndpointDetails, but it's not equivalent to a target
> hostname.
> 
> Francisco A. Lozano

In 5.x one can get those details directly from the request object. See
HttpRequest#getScheme and HttpRequest#getAuthority. 

Oleg

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