hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Francois-Xavier Bonnet (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPCLIENT-1325) Using a HttpRequest that is not an HttpUriRequest when host in URI is not target host results in an invalid request
Date Thu, 21 Feb 2013 14:52:13 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1325?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13583241#comment-13583241

Francois-Xavier Bonnet commented on HTTPCLIENT-1325:

You are right, now I remember these discussions about URI syntax.
So we cannot parse the uri with java.net.URI class.

I can see several options:
* no change in the code but a notice in method org.apache.http.impl.client.CloseableHttpClient.execute(HttpHost,
HttpRequest) javadoc that HttpHost is going to be used as the target server AND as the "Host"
* change the code to try to parse the uri with java.net.URI class anyway, but if it fails,
silently fall back to HttpHost
* try to extract the host without using java.net.URI class in a way that allows anything in
the uri after the scheme+host+port part

You opinion?

> Using a HttpRequest that is not an HttpUriRequest when host in URI is not target host
results in an invalid request
> -------------------------------------------------------------------------------------------------------------------
>                 Key: HTTPCLIENT-1325
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1325
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 4.3 Alpha1
>            Reporter: Francois-Xavier Bonnet
> Using the following code:
>         CloseableHttpClient httpClient = HttpClientBuilder.create().build();
>         HttpHost httpHost = new HttpHost("", 80, "http");
>         HttpRequest request = new BasicHttpRequest("GET", "http://www.foo.com/test");
>         httpClient.execute(httpHost, request);
> HttpClient sends this request:
>         GET http://www.foo.com/test HTTP/1.1
>         Host:
>         Connection: Keep-Alive
>         User-Agent: Apache-HttpClient/4.3-alpha2-SNAPSHOT (java 1.5)
>         Accept-Encoding: gzip,deflate
> The host header is not consistent with the request URI. This is due to org.apache.http.impl.execchain.ProtocolExec:
>         HttpHost target = null;
>         if (virtualHost != null) {
>             target = virtualHost;
>         } else {
>             final HttpRequest original = request.getOriginal();
>             if (original instanceof HttpUriRequest) {
>                 final URI uri = ((HttpUriRequest) original).getURI();
>                 if (uri.isAbsolute()) {
>                     target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
>                 }
>             }
>         }
>         if (target == null) {
>             target = route.getTargetHost();
>         }
> So for a HttpUriRequest the host is taken from the URI but for other requests it is taken
from the target server.
> I think it should be taken from the target server only if it cannot be determined from
the URI (non-absolute URI).
> I will fix this.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

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

View raw message