Skip to content

Commit

Permalink
fix(http): Be sure to add the port number to the HOST header if nonstd
Browse files Browse the repository at this point in the history
According to the spec, we need to add the HOST header with the port-number if a
nonstd port number is used.

This was discovered, as for the 1.7.x client setup, the download URL was
returned for a signed link with the port number in the signature, but we did not
add it as a part of the HOST header we set in the HTTP client.

Ticket: None
Changelog: None

Signed-off-by: Ole Petter <[email protected]>
  • Loading branch information
oleorhagen committed Nov 28, 2023
1 parent 4c74a64 commit f292fb8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/common/http/platform/beast/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ error::Error Client::Initialize() {
return error::NoError;
}

// Create the HOST header according to:
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23
// In short: Add the port-number if it is non-standard HTTP
static string CreateHOSTAddress(OutgoingRequestPtr req) {
if (req->GetPort() == 80 || req->GetPort() == 443) {
return req->GetHost();
}
return req->GetHost() + ":" + to_string(req->GetPort());
}

error::Error Client::AsyncCall(
OutgoingRequestPtr req, ResponseHandler header_handler, ResponseHandler body_handler) {
auto err = Initialize();
Expand Down Expand Up @@ -402,7 +412,10 @@ error::Error Client::AsyncCall(

// NOTE: The AWS loadbalancer requires that the HOST header always be set, in order for the
// request to route to our k8s cluster. Set this in all cases.
req->SetHeader("HOST", req->address_.host);
const string header_url = CreateHOSTAddress(req);
req->SetHeader("HOST", header_url);

log::Trace("Setting HOST address: " + header_url);

header_handler_ = header_handler;
body_handler_ = body_handler;
Expand Down

0 comments on commit f292fb8

Please sign in to comment.