Skip to content

Commit 537455b

Browse files
AllanZhengYPsrchase
authored andcommitted
feat: add a middleware inserting right host header (#567)
1 parent 263f665 commit 537455b

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ describe("NodeHttpHandler", () => {
4141
afterAll(() => {
4242
mockHttpServer.close();
4343
});
44+
it("has metadata", () => {
45+
const nodeHttpHandler = new NodeHttpHandler();
46+
expect(nodeHttpHandler.metadata.handlerProtocol).toContain("http/1.1");
47+
});
4448
it("can send http requests", async () => {
4549
const mockResponse = {
4650
statusCode: 200,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export class NodeHttpHandler implements HttpHandler {
3333
private readonly httpsAgent: https.Agent;
3434
private readonly connectionTimeout?: number;
3535
private readonly socketTimeout?: number;
36+
// Node http handler is hard-coded to http/1.1: https://github.com/nodejs/node/blob/ff5664b83b89c55e4ab5d5f60068fb457f1f5872/lib/_http_server.js#L286
37+
public readonly metadata = { handlerProtocol: "http/1.1" };
3638

3739
constructor({
3840
connectionTimeout,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ describe("NodeHttp2Handler", () => {
4444
mockH2Server.close();
4545
});
4646

47+
it("has metadata", () => {
48+
expect(nodeH2Handler.metadata.handlerProtocol).toContain("h2");
49+
});
50+
4751
describe("connectionPool", () => {
4852
it("is empty on initialization", () => {
4953
// @ts-ignore: access private property

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface NodeHttp2Options {
2727

2828
export class NodeHttp2Handler implements HttpHandler {
2929
private readonly connectionPool: Map<string, ClientHttp2Session>;
30+
public readonly metadata = { handlerProtocol: "h2" };
3031

3132
constructor(private readonly http2Options: NodeHttp2Options = {}) {
3233
this.connectionPool = new Map<string, ClientHttp2Session>();

packages/smithy-client/src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class Client<
7070
optionsOrCb?: HandlerOptions | ((err: any, data?: OutputType) => void),
7171
cb?: (err: any, data?: OutputType) => void
7272
): Promise<OutputType> | void {
73-
const options = typeof optionsOrCb !== "function" ? optionsOrCb : {};
73+
const options = typeof optionsOrCb !== "function" ? optionsOrCb : undefined;
7474
const callback =
7575
typeof optionsOrCb === "function"
7676
? (optionsOrCb as ((err: any, data?: OutputType) => void))

0 commit comments

Comments
 (0)