Skip to content

Commit

Permalink
Use host in Host header instead of domain
Browse files Browse the repository at this point in the history
  • Loading branch information
elnormous committed Sep 16, 2021
1 parent 156e290 commit cdaa3cd
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions include/HTTPRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,24 +493,27 @@ namespace http

if (pathPosition == std::string::npos)
{
domain = path;
host = path;
path = "/";
}
else
{
domain = path.substr(0, pathPosition);
host = path.substr(0, pathPosition);
path = path.substr(pathPosition);
}

const auto portPosition = domain.find(':');
const auto portPosition = host.find(':');

if (portPosition != std::string::npos)
{
port = domain.substr(portPosition + 1);
domain.resize(portPosition);
domain = host.substr(0, portPosition);
port = host.substr(portPosition + 1);
}
else
{
domain = host;
port = "80";
}
}

Response send(const std::string& method = "GET",
Expand Down Expand Up @@ -550,8 +553,8 @@ namespace http
for (const auto& header : headers)
headerData += header + "\r\n";

// RFC 7230, 3.2. Header Fields
headerData += "Host: " + domain + "\r\n"
// RFC 7230, 3.2. Header Fields
headerData += "Host: " + host + "\r\n"
"Content-Length: " + std::to_string(body.size()) + "\r\n"
"\r\n";

Expand Down Expand Up @@ -750,6 +753,7 @@ namespace http
#endif // _WIN32
InternetProtocol internetProtocol;
std::string scheme;
std::string host;
std::string domain;
std::string port;
std::string path;
Expand Down

0 comments on commit cdaa3cd

Please sign in to comment.