You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Omar BENHAMID (JIRA)" <ji...@apache.org> on 2009/02/26 15:37:02 UTC

[jira] Created: (HTTPCLIENT-830) Wrong Host header generated when manually set VirtualHost has a port

Wrong Host header generated when manually set VirtualHost has a port
--------------------------------------------------------------------

                 Key: HTTPCLIENT-830
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-830
             Project: HttpComponents HttpClient
          Issue Type: Bug
          Components: HttpClient
    Affects Versions: 3.1 Final
         Environment: Any
            Reporter: Omar BENHAMID


Implementing webassembletool proxy fonctionality, we need to set both Hostname and Port for the virtual host statement.
HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection) always adds connection port to the 'Host:' header if port is not the default for the protocol.

I would suggest adding this to the method : 

// Do not try to set port if already set in virtual host
if(host.indexOf(':') >= 0)  {
    setRequestHeader("Host", host);
    return;
}

like this :
 protected void addHostRequestHeader(HttpState state, HttpConnection conn)
    throws IOException, HttpException {
        LOG.trace("enter HttpMethodBase.addHostRequestHeader(HttpState, "
                  + "HttpConnection)");

        // Per 19.6.1.1 of RFC 2616, it is legal for HTTP/1.0 based
        // applications to send the Host request-header.
        // TODO: Add the ability to disable the sending of this header for
        //       HTTP/1.0 requests.
        String host = this.params.getVirtualHost();
        if (host != null) {
            LOG.debug("Using virtual host name: " + host);
        } else {
            host = conn.getHost();
        }
        // Do not try to set port if already set in virtual host
        if(host.indexOf(':') >= 0)  {
                setRequestHeader("Host", host);
                return;
        }
        
        int port = conn.getPort();

        // Note: RFC 2616 uses the term "internet host name" for what goes on the
        // host line.  It would seem to imply that host should be blank if the
        // host is a number instead of an name.  Based on the behavior of web
        // browsers, and the fact that RFC 2616 never defines the phrase "internet
        // host name", and the bad behavior of HttpClient that follows if we
        // send blank, I interpret this as a small misstatement in the RFC, where
        // they meant to say "internet host".  So IP numbers get sent as host
        // entries too. -- Eric Johnson 12/13/2002
        if (LOG.isDebugEnabled()) {
            LOG.debug("Adding Host request header");
        }

        //appends the port only if not using the default port for the protocol
        if (conn.getProtocol().getDefaultPort() != port) {
            host += (":" + port);
        }

        setRequestHeader("Host", host);
    }



-- 
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


[jira] Resolved: (HTTPCLIENT-830) Wrong Host header generated when manually set VirtualHost has a port

Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HTTPCLIENT-830?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCLIENT-830.
------------------------------------------

    Resolution: Won't Fix

Omar

There will be no fixes in the 3.x codeline other than for security / critical issues. HttpClient 3.x is pretty much near its end of life.

HttpClient 4.0 has a much more flexible API allowing the standard protocol interceptor for Host request headers be replaced with a custom one.

Closing as WONTFIX.

Oleg

> Wrong Host header generated when manually set VirtualHost has a port
> --------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-830
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-830
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient
>    Affects Versions: 3.1 Final
>         Environment: Any
>            Reporter: Omar BENHAMID
>   Original Estimate: 0.25h
>  Remaining Estimate: 0.25h
>
> Implementing webassembletool proxy fonctionality, we need to set both Hostname and Port for the virtual host statement.
> HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection) always adds connection port to the 'Host:' header if port is not the default for the protocol.
> I would suggest adding this to the method : 
> // Do not try to set port if already set in virtual host
> if(host.indexOf(':') >= 0)  {
>     setRequestHeader("Host", host);
>     return;
> }
> like this :
>  protected void addHostRequestHeader(HttpState state, HttpConnection conn)
>     throws IOException, HttpException {
>         LOG.trace("enter HttpMethodBase.addHostRequestHeader(HttpState, "
>                   + "HttpConnection)");
>         // Per 19.6.1.1 of RFC 2616, it is legal for HTTP/1.0 based
>         // applications to send the Host request-header.
>         // TODO: Add the ability to disable the sending of this header for
>         //       HTTP/1.0 requests.
>         String host = this.params.getVirtualHost();
>         if (host != null) {
>             LOG.debug("Using virtual host name: " + host);
>         } else {
>             host = conn.getHost();
>         }
>         // Do not try to set port if already set in virtual host
>         if(host.indexOf(':') >= 0)  {
>                 setRequestHeader("Host", host);
>                 return;
>         }
>         
>         int port = conn.getPort();
>         // Note: RFC 2616 uses the term "internet host name" for what goes on the
>         // host line.  It would seem to imply that host should be blank if the
>         // host is a number instead of an name.  Based on the behavior of web
>         // browsers, and the fact that RFC 2616 never defines the phrase "internet
>         // host name", and the bad behavior of HttpClient that follows if we
>         // send blank, I interpret this as a small misstatement in the RFC, where
>         // they meant to say "internet host".  So IP numbers get sent as host
>         // entries too. -- Eric Johnson 12/13/2002
>         if (LOG.isDebugEnabled()) {
>             LOG.debug("Adding Host request header");
>         }
>         //appends the port only if not using the default port for the protocol
>         if (conn.getProtocol().getDefaultPort() != port) {
>             host += (":" + port);
>         }
>         setRequestHeader("Host", host);
>     }

-- 
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: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org