Skip to content

Commit 42881d2

Browse files
committed
The change in flatten_http_headers to omit adding Host header wasbreaking
windows clients. Instead, skip adding the host header when user has already specified one in the boost asio based clients without modifying flatten_http_headers.
1 parent 9eebbd3 commit 42881d2

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

Release/include/cpprest/details/http_client_impl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ static utility::string_t flatten_http_headers(const http_headers &headers)
5757
utility::string_t flattened_headers;
5858
for(auto iter = headers.begin(); iter != headers.end(); ++iter)
5959
{
60-
utility::string_t header_name = iter->first;
61-
if (utility::details::str_icmp(header_name, header_names::host)) {
62-
continue;
63-
}
6460
flattened_headers.append(iter->first);
6561
flattened_headers.push_back(':');
6662
flattened_headers.append(iter->second);

Release/src/http/client/http_client_asio.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,19 +395,17 @@ class asio_context : public request_context, public std::enable_shared_from_this
395395
request_stream.imbue(std::locale::classic());
396396

397397
request_stream << method << " " << encoded_resource << " " << "HTTP/1.1" << CRLF;
398-
request_stream << "Host: ";
399398

400399
int port = base_uri.port();
401400
if (base_uri.is_port_default())
402401
{
403402
port = (m_connection->is_ssl() ? 443 : 80);
404403
}
405404

406-
std::string specified_host_header;
407-
if (m_request.headers().match(header_names::host, specified_host_header)) {
408-
request_stream << specified_host_header << CRLF;
409-
} else {
410-
request_stream << host << ":" << port << CRLF;
405+
// Add the Host header if user has not specified it explicitly
406+
if (!m_request.headers().has(header_names::host))
407+
{
408+
request_stream << "Host: " << host << ":" << port << CRLF;
411409
}
412410

413411
// Extra request headers are constructed here.

0 commit comments

Comments
 (0)