Skip to content

Commit

Permalink
add unit test, changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Sep 20, 2024
1 parent 3647425 commit 60dc1d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
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
5 changes: 3 additions & 2 deletions packages/node-http-handler/src/node-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Logger, NodeHttpHandlerOptions } from "@smithy/types";
import { HttpHandlerOptions, Provider } from "@smithy/types";
import { Agent as hAgent, request as hRequest } from "http";
import { Agent as hsAgent, request as hsRequest, RequestOptions } from "https";
import { urlToHttpOptions } from "url";

Check failure on line 7 in packages/node-http-handler/src/node-http-handler.ts

View workflow job for this annotation

GitHub Actions / TypeScript Lint

'urlToHttpOptions' is defined but never used

import { NODEJS_TIMEOUT_ERROR_CODES } from "./constants";
import { getTransformedHeaders } from "./get-transformed-headers";
Expand Down Expand Up @@ -210,8 +211,8 @@ or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler conf
path += `#${request.fragment}`;
}

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

0 comments on commit 60dc1d5

Please sign in to comment.