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

Commit 1056bd2

Browse files
committed
Now adds port to host request header field value only if the port is non-default
1 parent 7605710 commit 1056bd2

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

client_http.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ namespace SimpleWeb {
361361

362362
std::string host;
363363
unsigned short port;
364+
unsigned short default_port;
364365

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

@@ -372,7 +373,7 @@ namespace SimpleWeb {
372373
std::size_t concurrent_synchronous_requests = 0;
373374
std::mutex concurrent_synchronous_requests_mutex;
374375

375-
ClientBase(const std::string &host_port, unsigned short default_port) noexcept : handler_runner(new ScopeRunner()) {
376+
ClientBase(const std::string &host_port, unsigned short default_port) noexcept : default_port(default_port), handler_runner(new ScopeRunner()) {
376377
auto parsed_host_port = parse_host_port(host_port, default_port);
377378
host = parsed_host_port.first;
378379
port = parsed_host_port.second;
@@ -425,7 +426,10 @@ namespace SimpleWeb {
425426
std::unique_ptr<asio::streambuf> streambuf(new asio::streambuf());
426427
std::ostream write_stream(streambuf.get());
427428
write_stream << method << " " << corrected_path << " HTTP/1.1\r\n";
428-
write_stream << "Host: " << host << ":" << std::to_string(port) << "\r\n";
429+
write_stream << "Host: " << host;
430+
if(port != default_port)
431+
write_stream << ':' << std::to_string(port);
432+
write_stream << "\r\n";
429433
for(auto &h : header)
430434
write_stream << h.first << ": " << h.second << "\r\n";
431435
return streambuf;

0 commit comments

Comments
 (0)