Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Development/cpprest/http_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ namespace web
if (req.headers().end() != header)
{
auto first = header->second.substr(0, header->second.find(','));
auto colon = first.find(':');
// an IPv6 address is enclosed in square brackets, e.g. "[2001:db8::1]:42", so look for the port after the closing bracket
// see https://tools.ietf.org/html/rfc3986#section-3.2.2
const auto bracket = first.find(']');
auto colon = first.find(':', utility::string_t::npos != bracket ? bracket : 0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe

Suggested change
auto colon = first.find(':', utility::string_t::npos != bracket ? bracket : 0);
const auto colon = first.find(':', bracket + 1);

;-)

if (utility::string_t::npos == colon) return{ std::move(first), 0 };
return{ first.substr(0, colon), utility::conversions::details::scan_string(first.substr(colon + 1), 0) };
}
Expand Down
6 changes: 6 additions & 0 deletions Development/cpprest/test/http_utils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ BST_TEST_CASE(testGetHostPort)
req.headers().add(U("Host"), U("29.31.37.41:42"));
BST_REQUIRE_EQUAL(std::make_pair(utility::string_t{ U("29.31.37.41") }, 42), web::http::get_host_port(req));
}
// IPv6 address and port
{
web::http::http_request req;
req.headers().add(U("Host"), U("[2001:db8::1]:42"));
BST_REQUIRE_EQUAL(std::make_pair(utility::string_t{ U("[2001:db8::1]") }, 42), web::http::get_host_port(req));
}

// 'X-Forwarded-Host'

Expand Down