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:
@@ -81,6 +81,9 @@ private:
|
|||||||
void _SetResultStatusCode(int32 statusCode);
|
void _SetResultStatusCode(int32 statusCode);
|
||||||
BString& _ResultStatusText();
|
BString& _ResultStatusText();
|
||||||
|
|
||||||
|
// Utility methods
|
||||||
|
bool _IsDefaultPort();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BAbstractSocket* fSocket;
|
BAbstractSocket* fSocket;
|
||||||
BNetworkAddress fRemoteAddr;
|
BNetworkAddress fRemoteAddr;
|
||||||
|
|||||||
@@ -815,7 +815,11 @@ BHttpRequest::_SendHeaders()
|
|||||||
{
|
{
|
||||||
// HTTP 1.1 additional headers
|
// HTTP 1.1 additional headers
|
||||||
if (fHttpVersion == B_HTTP_11) {
|
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", "*/*");
|
||||||
fOutputHeaders.AddHeader("Accept-Encoding", "gzip,deflate");
|
fOutputHeaders.AddHeader("Accept-Encoding", "gzip,deflate");
|
||||||
@@ -1041,3 +1045,15 @@ BHttpRequest::_ResultStatusText()
|
|||||||
{
|
{
|
||||||
return fResult.fStatusString;
|
return fResult.fStatusString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool BHttpRequest::_IsDefaultPort()
|
||||||
|
{
|
||||||
|
if (fSSL && Url().Port() == 443)
|
||||||
|
return true;
|
||||||
|
if (!fSSL && Url().Port() == 80)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user