From 1056bd2e70c6abdd6a334d57247f1ea18bab45ef Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 14 Feb 2018 12:47:58 +0100 Subject: [PATCH] Now adds port to host request header field value only if the port is non-default --- client_http.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index d1c32d03..baece6f5 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -361,6 +361,7 @@ namespace SimpleWeb { std::string host; unsigned short port; + unsigned short default_port; std::unique_ptr query; @@ -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; @@ -425,7 +426,10 @@ namespace SimpleWeb { std::unique_ptr 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;