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 Joan Balaguero <jo...@grupoventus.com> on 2012/10/10 16:53:02 UTC

HttpHost thread-safe?

Hello,

 

When I implement a router planner like this:

 

( . . . )

public HttpRoute determineRoute(HttpHost target, HttpRequest request,
HttpContext context) throws HttpException 

{

  boolean isHttps = "https".equalsIgnoreCase(target.getSchemeName());

  HttpHost proxy  = isHttps ? httpsProxy : httpProxy;

                

  if (proxy == null) return new HttpRoute(target, null, isHttps);

  return new HttpRoute(target, null, proxy, isHttps);

}

 

Can I pass to HttpRoute an already constructed HttpHost (like above)? Or
should I build a new HttpHost like “return new HttpRoute(target, null, new
HttpHost(proxy.getHostName(), proxy.getPort(), proxy.getSchemeName()),
isHttps);” ?

 

Thanks,

 

Joan.

 


Re: HttpHost thread-safe?

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2012-10-10 at 16:53 +0200, Joan Balaguero wrote:
> Hello,
> 
>  
> 
> When I implement a router planner like this:
> 
>  
> 
> ( . . . )
> 
> public HttpRoute determineRoute(HttpHost target, HttpRequest request,
> HttpContext context) throws HttpException 
> 
> {
> 
>   boolean isHttps = "https".equalsIgnoreCase(target.getSchemeName());
> 
>   HttpHost proxy  = isHttps ? httpsProxy : httpProxy;
> 
>                 
> 
>   if (proxy == null) return new HttpRoute(target, null, isHttps);
> 
>   return new HttpRoute(target, null, proxy, isHttps);
> 
> }
> 
>  
> 
> Can I pass to HttpRoute an already constructed HttpHost (like above)? Or
> should I build a new HttpHost like “return new HttpRoute(target, null, new
> HttpHost(proxy.getHostName(), proxy.getPort(), proxy.getSchemeName()),
> isHttps);” ?
> 

HttpHost is immutable and as such can be safely accessed by multiple
threads.

Oleg



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