Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Now adds port to host request header field value only if the port is …
Browse files Browse the repository at this point in the history
…non-default
  • Loading branch information
eidheim committed Feb 14, 2018
1 parent 7605710 commit 1056bd2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client_http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ namespace SimpleWeb {

std::string host;
unsigned short port;
unsigned short default_port;

std::unique_ptr<asio::ip::tcp::resolver::query> query;

Expand All @@ -372,7 +373,7 @@ namespace SimpleWeb {
std::size_t concurrent_synchronous_requests = 0;
std::mutex concurrent_synchronous_requests_mutex;

ClientBase(const std::string &host_port, unsigned short default_port) noexcept : handler_runner(new ScopeRunner()) {
ClientBase(const std::string &host_port, unsigned short default_port) noexcept : default_port(default_port), handler_runner(new ScopeRunner()) {
auto parsed_host_port = parse_host_port(host_port, default_port);
host = parsed_host_port.first;
port = parsed_host_port.second;
Expand Down Expand Up @@ -425,7 +426,10 @@ namespace SimpleWeb {
std::unique_ptr<asio::streambuf> streambuf(new asio::streambuf());
std::ostream write_stream(streambuf.get());
write_stream << method << " " << corrected_path << " HTTP/1.1\r\n";
write_stream << "Host: " << host << ":" << std::to_string(port) << "\r\n";
write_stream << "Host: " << host;
if(port != default_port)
write_stream << ':' << std::to_string(port);
write_stream << "\r\n";
for(auto &h : header)
write_stream << h.first << ": " << h.second << "\r\n";
return streambuf;
Expand Down

0 comments on commit 1056bd2

Please sign in to comment.