Add the port to the HTTP Host header when needed.

* When the port is not the default one, it must be added to the "Host"
header so the server knows what we're connecting to.

Fixes #11070.
This commit is contained in:
Adrien Destugues 2014-07-28 11:05:58 +02:00
parent ae2cdda736
commit 021ebc2f8c
2 changed files with 20 additions and 1 deletions

View File

@ -81,6 +81,9 @@ private:
void _SetResultStatusCode(int32 statusCode);
BString& _ResultStatusText();
// Utility methods
bool _IsDefaultPort();
private:
BAbstractSocket* fSocket;
BNetworkAddress fRemoteAddr;

View File

@ -815,7 +815,11 @@ BHttpRequest::_SendHeaders()
{
// HTTP 1.1 additional headers
if (fHttpVersion == B_HTTP_11) {
fOutputHeaders.AddHeader("Host", Url().Host());
BString host = Url().Host();
if (Url().HasPort() && !_IsDefaultPort())
host << ':' << Url().Port();
fOutputHeaders.AddHeader("Host", host);
fOutputHeaders.AddHeader("Accept", "*/*");
fOutputHeaders.AddHeader("Accept-Encoding", "gzip,deflate");
@ -1041,3 +1045,15 @@ BHttpRequest::_ResultStatusText()
{
return fResult.fStatusString;
}
bool BHttpRequest::_IsDefaultPort()
{
if (fSSL && Url().Port() == 443)
return true;
if (!fSSL && Url().Port() == 80)
return true;
return false;
}