hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oleg Kalnichevski (JIRA)" <j...@apache.org>
Subject [jira] Resolved: (HTTPCLIENT-660) Should host header be send in all lowercase
Date Sat, 30 Jun 2007 16:24:04 GMT

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-660?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Oleg Kalnichevski resolved HTTPCLIENT-660.
------------------------------------------

    Resolution: Won't Fix

Actually it is now _super_ trivial to add this as an optional behavior through a custom request
interceptor. So, there is not real benefit of doing it per default. 

Ain't new API cool?

Oleg
---------------------------------------
DefaultHttpClient httpclient = new DefaultHttpClient(params);

HttpGet httpget = new HttpGet("http://WwW.GooGle.COM/");

httpclient.addRequestInterceptor(new HttpRequestInterceptor() {

    public void process(
            final HttpRequest request, 
            final HttpContext context) throws HttpException, IOException {
        Header header = request.getFirstHeader("Host");
        if (header != null) {
            String s = header.getValue().toLowerCase();
            request.setHeader("Host", s);
        }
    }
    
});

System.out.println("executing request: " + httpget.getRequestLine());
HttpResponse response = httpclient.execute(httpget);

System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println("----------------------------------------");

HttpEntity entity = response.getEntity();
if (entity != null) {
    entity.consumeContent();
}
---------------------------------------
executing request: GET http://WwW.GooGle.COM/ HTTP/1.1
...
[DEBUG] wire - >> "GET / HTTP/1.1[EOL]"
[DEBUG] wire - >> "Host: www.google.com[EOL]"
[DEBUG] wire - >> "Connection: Keep-Alive[EOL]"
[DEBUG] wire - >> "User-Agent: Apache-HttpClient/4.0[EOL]"
[DEBUG] wire - >> "[EOL]"


> Should host header be send in all lowercase
> -------------------------------------------
>
>                 Key: HTTPCLIENT-660
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-660
>             Project: HttpComponents HttpClient
>          Issue Type: Improvement
>    Affects Versions: 3.1 RC1
>         Environment: Windows XP
> Sun 1.6_01 JVM
>            Reporter: Daniel Hopper
>            Priority: Minor
>             Fix For: 4.0 Alpha 1
>
>
> Current the host header is sent as is from any 302 or standard url request.  Now obviously
according to the spec host names should be compared case insensitive but this isn't always
the case.  Most if not all browser will always lowercase the domain names when a  request
is sent.  This problem happened when we were trying to valid urls from merchants.  The one
in particular was
> http://www.jdoqocy.com/click-1916095-10274762
> which will finally end up redirecting to 
> http://www.BestArt.com/default.asp?aff=1
> With that case in the domain name and that is the way the host header is written.  This
will actually return a 404 if you request this URL from commons-httpclient, but will give
no problem with a request in IE or FireFox b/c they lowercase the domain name before sending.
 This is b/c its trying to match BestArt instead of bestart.  Now I know this isn't a problem
with commons-httpclient but rather how they have their server configured.  I think it would
be nice to provide a property for this configuration settting or rather follow the way all
browsers handle this as well.
> I know this isn't a major issue and was able to get around it by just sub classing the
GetMethod and overriding addRequestHeader.
> @Override
> public void addRequestHeader(Header header) {
> 	if(header.getName().equalsIgnoreCase("host")) {
> 		header = new Header(header.getName(), header.getValue().toLowerCase(), header.isAutogenerated());
> 	}
> 	super.addRequestHeader(header);
> }
> Just thought this may be of interest as well as it is quite a simple fix.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org


Mime
View raw message