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