[prev in list] [next in list] [prev in thread] [next in thread] 

List:       httpclient-commons-dev
Subject:    Re: Trimming port 80 in request Host header
From:       alin vasile <alinachegalati () yahoo ! com>
Date:       2011-03-14 20:08:47
Message-ID: 987258.93696.qm () web110507 ! mail ! gq1 ! yahoo ! com
[Download RAW message or body]


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 <olegk@apache.org>
To: alin vasile <alinachegalati@yahoo.com>
Cc: "dev@hc.apache.org" <dev@hc.apache.org>
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


      



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic