Hi Oleg,

    Thanks for your advice. It proves that that method family is final and the 
determineTarget(HttpUriRequest request) method, where would be the ideal 
routine for the tweak, is static. 

    This was more a suggestion/nice-to-have than a real isue, so one can live 
happily with it. 

Regards,
Alin


________________________________
From: Oleg Kalnichevski <[email protected]>
To: alin vasile <[email protected]>
Cc: "[email protected]" <[email protected]>
Sent: Monday, March 14, 2011 11:39 AM
Subject: Re: Trimming port 80 in request Host header

On Sat, 2011-03-12 at 03:20 -0800, alin vasile wrote:
> Hi,
> 
>    I noticed that when the default port is specified explicitly in the 
>requested URL address, http-client 4.1  will use it in the 'Host' header. The 
>HTTP 1.1 specification doesn't deny this, but the same scenario can't be 
>reproduced with any modern browser. Would be any issues if httpclient will 
>have the same behaviour?
> 
> Sample code:
> 
> DefaultHttpClient httpclient = new DefaultHttpClient();
> HttpGet httpget = new HttpGet("http://www.google.ro:80/";);  
> HttpResponse response = httpclient.execute(httpget);
> 
> Log:
> [DEBUG] DefaultClientConnection - Sending request: GET / HTTP/1.1
> [DEBUG] headers - >> GET / HTTP/1.1
> [DEBUG] headers - >> Host: www.google.ro:80
> [DEBUG] headers - >> Connection: Keep-Alive
> [DEBUG] headers - >> User-Agent: Apache-HttpClient/4.1 (java 1.5)
> 
> And some added test cases in 
> org.apache.http.protocol.TestStandardInterceptors that currently fail:
> 
> public void testRequestTargetHostPort443Generated() throws Exception {
>         HttpContext context = new BasicHttpContext(null);
>         HttpHost host = new HttpHost("somehost", 443, "https");
>         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
>         BasicHttpRequest request = new BasicHttpRequest("GET", "/");
>         RequestTargetHost interceptor = new RequestTargetHost();
>         interceptor.process(request, context);
>         Header header = request.getFirstHeader(HTTP.TARGET_HOST);
>         assertNotNull(header);
>         assertEquals("somehost", header.getValue());
>     }
>    
>     public void testRequestTargetHostPort80Generated() throws Exception {
>         HttpContext context = new BasicHttpContext(null);
>         HttpHost host = new HttpHost("somehost", 80, "http");
>         context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, host);
>         BasicHttpRequest request = new BasicHttpRequest("GET", "/");
>         RequestTargetHost interceptor = new RequestTargetHost();
>         interceptor.process(request, context);
>         Header header = request.getFirstHeader(HTTP.TARGET_HOST);
>         assertNotNull(header);
>         assertEquals("somehost", header.getValue());
>     }
> 
> Regards,
> Alin
> 
> 

Alin

I do not think that a core protocol interceptor is the right place for
such a tweak. The problem can be dealt with in a much better way by
overriding the AbstractHttpClient#execute(HttpUriRequest) method [1] and
stripping away default ports for known schemes when building HttpHost
instance from the request URI. 

Hope this helps

Oleg

[1]
http://hc.apache.org/httpcomponents-client-ga/httpclient/xref/org/apache/http/impl/client/AbstractHttpClient.html#745
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


      

Reply via email to