Skip to content

Commit 08fbedf

Browse files
Defmankuhe
andauthored
fix(node-http-handler): fix invalid usage of parsed url (#1408)
* fix(node-http-handler): fix invalid usage of parsed url * add unit test, changeset --------- Co-authored-by: George Fu <[email protected]>
1 parent b12dc1d commit 08fbedf

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

.changeset/gold-bugs-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@smithy/node-http-handler": patch
3+
---
4+
5+
remove brackets from hostname

packages/node-http-handler/src/node-http-handler.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,24 @@ describe("NodeHttpHandler", () => {
153153
expect(hRequestSpy.mock.calls[0][0]?.port).toEqual(1234);
154154
expect(hRequestSpy.mock.calls[0][0]?.path).toEqual("/some/path?some=query#fragment");
155155
});
156+
157+
it("removes brackets from hostname", async () => {
158+
const nodeHttpHandler = new NodeHttpHandler({});
159+
const httpRequest = {
160+
protocol: "http:",
161+
username: "username",
162+
password: "password",
163+
hostname: "[host]",
164+
port: 1234,
165+
path: "/some/path",
166+
query: {
167+
some: "query",
168+
},
169+
fragment: "fragment",
170+
};
171+
await nodeHttpHandler.handle(httpRequest as any);
172+
expect(hRequestSpy.mock.calls[0][0]?.host).toEqual("host");
173+
});
156174
});
157175
});
158176

packages/node-http-handler/src/node-http-handler.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,17 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
209209
if (request.fragment) {
210210
path += `#${request.fragment}`;
211211
}
212+
213+
let hostname = request.hostname ?? "";
214+
if (hostname[0] === "[" && hostname.endsWith("]")) {
215+
hostname = request.hostname.slice(1, -1);
216+
} else {
217+
hostname = request.hostname;
218+
}
219+
212220
const nodeHttpsOptions: RequestOptions = {
213221
headers: request.headers,
214-
host: request.hostname,
222+
host: hostname,
215223
method: request.method,
216224
path,
217225
port: request.port,

0 commit comments

Comments
 (0)