Skip to content

Commit

Permalink
feat(s3-request-presigner): automatically add host header (#1988)
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanZhengYP committed Feb 9, 2021
1 parent a008d23 commit cd50eeb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/s3-request-presigner/src/presigner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ describe("s3 presigner", () => {
expect(signedHeaders).toContain("x-amz-server-side-encryption");
expect(signedHeaders).toContain("x-amz-server-side-encryption-customer-algorithm");
});

it("should inject host header if not supplied", async () => {
const signer = new S3RequestPresigner(s3ResolvedConfig);
const signed = await signer.presign(minimalRequest);
expect(signed.headers).toMatchObject({
host: minimalRequest.hostname,
});
});
});
3 changes: 3 additions & 0 deletions packages/s3-request-presigner/src/presigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export class S3RequestPresigner implements RequestPresigner {
unhoistableHeaders.add(header);
});
requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
if (!requestToSign.headers["host"]) {
requestToSign.headers.host = requestToSign.hostname;
}
return this.signer.presign(requestToSign, {
expiresIn: 900,
unsignableHeaders,
Expand Down

0 comments on commit cd50eeb

Please sign in to comment.