HTTP should contain port in 'Host' header (#427)
This commit is contained in:
parent
679ce519dd
commit
6cc21f3658
@ -139,8 +139,9 @@ namespace ix
|
||||
|
||||
std::string protocol, host, path, query;
|
||||
int port;
|
||||
bool isProtocolDefaultPort;
|
||||
|
||||
if (!UrlParser::parse(url, protocol, host, path, query, port))
|
||||
if (!UrlParser::parse(url, protocol, host, path, query, port, isProtocolDefaultPort))
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Cannot parse url: " << url;
|
||||
@ -173,7 +174,12 @@ namespace ix
|
||||
// Build request string
|
||||
std::stringstream ss;
|
||||
ss << verb << " " << path << " HTTP/1.1\r\n";
|
||||
ss << "Host: " << host << "\r\n";
|
||||
ss << "Host: " << host;
|
||||
if (!isProtocolDefaultPort)
|
||||
{
|
||||
ss << ":" << port;
|
||||
}
|
||||
ss << "\r\n";
|
||||
|
||||
#ifdef IXWEBSOCKET_USE_ZLIB
|
||||
if (args->compress && !args->onChunkCallback)
|
||||
|
@ -333,6 +333,19 @@ namespace
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
int getProtocolPort(const std::string& protocol)
|
||||
{
|
||||
if (protocol == "ws" || protocol == "http")
|
||||
{
|
||||
return 80;
|
||||
}
|
||||
else if (protocol == "wss" || protocol == "https")
|
||||
{
|
||||
return 443;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace ix
|
||||
@ -343,6 +356,18 @@ namespace ix
|
||||
std::string& path,
|
||||
std::string& query,
|
||||
int& port)
|
||||
{
|
||||
bool isProtocolDefaultPort;
|
||||
return parse(url, protocol, host, path, query, port, isProtocolDefaultPort);
|
||||
}
|
||||
|
||||
bool UrlParser::parse(const std::string& url,
|
||||
std::string& protocol,
|
||||
std::string& host,
|
||||
std::string& path,
|
||||
std::string& query,
|
||||
int& port,
|
||||
bool& isProtocolDefaultPort)
|
||||
{
|
||||
clParseURL res = clParseURL::ParseURL(url);
|
||||
|
||||
@ -356,23 +381,12 @@ namespace ix
|
||||
path = res.m_Path;
|
||||
query = res.m_Query;
|
||||
|
||||
const auto protocolPort = getProtocolPort(protocol);
|
||||
if (!res.GetPort(&port))
|
||||
{
|
||||
if (protocol == "ws" || protocol == "http")
|
||||
{
|
||||
port = 80;
|
||||
}
|
||||
else if (protocol == "wss" || protocol == "https")
|
||||
{
|
||||
port = 443;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid protocol. Should be caught by regex check
|
||||
// but this missing branch trigger cpplint linter.
|
||||
return false;
|
||||
}
|
||||
port = protocolPort;
|
||||
}
|
||||
isProtocolDefaultPort = port == protocolPort;
|
||||
|
||||
if (path.empty())
|
||||
{
|
||||
|
@ -19,5 +19,13 @@ namespace ix
|
||||
std::string& path,
|
||||
std::string& query,
|
||||
int& port);
|
||||
|
||||
static bool parse(const std::string& url,
|
||||
std::string& protocol,
|
||||
std::string& host,
|
||||
std::string& path,
|
||||
std::string& query,
|
||||
int& port,
|
||||
bool& isProtocolDefaultPort);
|
||||
};
|
||||
} // namespace ix
|
||||
|
Loading…
Reference in New Issue
Block a user