Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node-http-handler): fix invalid usage of parsed url #1408

Merged
merged 2 commits into from
Sep 20, 2024
Merged
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: 5 additions & 0 deletions .changeset/gold-bugs-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@smithy/node-http-handler": patch
---

remove brackets from hostname
18 changes: 18 additions & 0 deletions packages/node-http-handler/src/node-http-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ describe("NodeHttpHandler", () => {
expect(hRequestSpy.mock.calls[0][0]?.port).toEqual(1234);
expect(hRequestSpy.mock.calls[0][0]?.path).toEqual("/some/path?some=query#fragment");
});

it("removes brackets from hostname", async () => {
const nodeHttpHandler = new NodeHttpHandler({});
const httpRequest = {
protocol: "http:",
username: "username",
password: "password",
hostname: "[host]",
port: 1234,
path: "/some/path",
query: {
some: "query",
},
fragment: "fragment",
};
await nodeHttpHandler.handle(httpRequest as any);
expect(hRequestSpy.mock.calls[0][0]?.host).toEqual("host");
});
});
});

Expand Down
10 changes: 9 additions & 1 deletion packages/node-http-handler/src/node-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,17 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
if (request.fragment) {
path += `#${request.fragment}`;
}

let hostname = request.hostname ?? "";
if (hostname[0] === "[" && hostname.endsWith("]")) {
hostname = request.hostname.slice(1, -1);
} else {
hostname = request.hostname;
}

const nodeHttpsOptions: RequestOptions = {
headers: request.headers,
host: request.hostname,
host: hostname,
method: request.method,
path,
port: request.port,
Expand Down
Loading