Skip to content

Commit

Permalink
fix(middleware-host-header): populate :authority pseudo-header with a…
Browse files Browse the repository at this point in the history
…uthority section of target URI (#5369)
  • Loading branch information
siddsriv committed Oct 16, 2023
1 parent c361378 commit 242a32c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/middleware-host-header/src/index.spec.ts
Expand Up @@ -57,11 +57,12 @@ describe("hostHeaderMiddleware", () => {
input: {},
request: new HttpRequest({
hostname: "foo.amazonaws.com",
port: 8080,
headers: { host: "random host" },
}),
});
expect(mockNextHandler.mock.calls.length).toEqual(1);
expect(mockNextHandler.mock.calls[0][0].request.headers.host).not.toBeDefined();
expect(mockNextHandler.mock.calls[0][0].request.headers[":authority"]).toEqual("");
expect(mockNextHandler.mock.calls[0][0].request.headers[":authority"]).toEqual("foo.amazonaws.com:8080");
});
});
2 changes: 1 addition & 1 deletion packages/middleware-host-header/src/index.ts
Expand Up @@ -33,7 +33,7 @@ export const hostHeaderMiddleware =
//reference: https://nodejs.org/dist/latest-v13.x/docs/api/errors.html#ERR_HTTP2_INVALID_CONNECTION_HEADERS
if (handlerProtocol.indexOf("h2") >= 0 && !request.headers[":authority"]) {
delete request.headers["host"];
request.headers[":authority"] = "";
request.headers[":authority"] = request.hostname + (request.port ? ":" + request.port : "");
//non-H2 request and 'host' header is not set, set the 'host' header to request's hostname.
} else if (!request.headers["host"]) {
let host = request.hostname;
Expand Down

0 comments on commit 242a32c

Please sign in to comment.