Skip to content

Commit 638d40a

Browse files
garethsblo-simon
authored andcommitted
Add port to the Host header
1 parent 62a9165 commit 638d40a

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Development/nmos/client_utils.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,22 @@ namespace nmos
258258

259259
namespace details
260260
{
261-
// make a client for the specified base_uri and config, with Host header sneakily stashed in user info
261+
// make a client for the specified base_uri and config, with host name for the Host header sneakily stashed in user info
262262
std::unique_ptr<web::http::client::http_client> make_http_client(const web::uri& base_uri, const web::http::client::http_client_config& client_config)
263263
{
264-
// unstash the Host header
264+
// unstash the host name for the Host header
265265
// cf. nmos::details::resolve_service
266-
const auto& host_name = base_uri.user_info();
267266
std::unique_ptr<web::http::client::http_client> client(new web::http::client::http_client(web::uri_builder(base_uri).set_user_info({}).to_uri(), client_config));
268-
if (!host_name.empty())
267+
if (!base_uri.user_info().empty())
269268
{
270-
client->add_handler([host_name](web::http::http_request request, std::shared_ptr<web::http::http_pipeline_stage> next_stage) -> pplx::task<web::http::http_response>
269+
auto host = base_uri.user_info();
270+
if (base_uri.port() > 0)
271271
{
272-
request.headers().add(web::http::header_names::host, host_name);
272+
host.append(U(":")).append(utility::conversions::details::to_string_t(base_uri.port()));
273+
}
274+
client->add_handler([host](web::http::http_request request, std::shared_ptr<web::http::http_pipeline_stage> next_stage) -> pplx::task<web::http::http_response>
275+
{
276+
request.headers().add(web::http::header_names::host, host);
273277
return next_stage->propagate(request);
274278
});
275279
}

Development/nmos/client_utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace nmos
3333

3434
namespace details
3535
{
36-
// make a client for the specified base_uri and config, with Host header sneakily stashed in user info
36+
// make a client for the specified base_uri and config, with host name for the Host header sneakily stashed in user info
3737
std::unique_ptr<web::http::client::http_client> make_http_client(const web::uri& base_uri_with_host_name_in_user_info, const web::http::client::http_client_config& client_config);
3838
}
3939

Development/nmos/mdns.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ namespace nmos
561561

562562
for (const auto& ip_address : resolved.ip_addresses)
563563
{
564-
// sneakily stash the Host header in user info
564+
// sneakily stash the host name for the Host header in user info
565565
// cf. nmos::details::make_http_client
566566
results->push_back({ { *resolved_ver, resolved_pri }, resolved_uri
567567
.set_user_info(host_name)

0 commit comments

Comments
 (0)