diff --git a/.changeset/friendly-parents-compare.md b/.changeset/friendly-parents-compare.md new file mode 100644 index 00000000000..bdec548a97b --- /dev/null +++ b/.changeset/friendly-parents-compare.md @@ -0,0 +1,5 @@ +--- +"@smithy/core": patch +--- + +copy input headers when building RPCv2 CBOR request diff --git a/packages/core/src/submodules/cbor/parseCborBody.spec.ts b/packages/core/src/submodules/cbor/parseCborBody.spec.ts new file mode 100644 index 00000000000..2b3f746652d --- /dev/null +++ b/packages/core/src/submodules/cbor/parseCborBody.spec.ts @@ -0,0 +1,32 @@ +import { buildHttpRpcRequest } from "./parseCborBody"; + +import { describe, test as it, expect } from "vitest"; + +describe("buildHttpRpcRequest", () => { + it("should copy the input headers", async () => { + const headers = { + "content-type": "application/cbor", + "smithy-protocol": "rpc-v2-cbor", + accept: "application/cbor", + "content-length": "0", + }; + + const request = await buildHttpRpcRequest( + { + async endpoint() { + return { + hostname: "https://localhost", + path: "/", + }; + }, + } as any, + headers, + "/", + "", + "" + ); + + expect(request.headers).toEqual(headers); + expect(request.headers).not.toBe(headers); + }); +}); diff --git a/packages/core/src/submodules/cbor/parseCborBody.ts b/packages/core/src/submodules/cbor/parseCborBody.ts index d0605fd1bdb..8aa6e1c84cb 100644 --- a/packages/core/src/submodules/cbor/parseCborBody.ts +++ b/packages/core/src/submodules/cbor/parseCborBody.ts @@ -100,7 +100,10 @@ export const buildHttpRpcRequest = async ( port, method: "POST", path: basePath.endsWith("/") ? basePath.slice(0, -1) + path : basePath + path, - headers, + headers: { + // intentional copy. + ...headers, + }, }; if (resolvedHostname !== undefined) { contents.hostname = resolvedHostname;