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: [email protected]
For additional commands, e-mail: [email protected]