File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
packages/signature-v4/src Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 11import { HttpRequest } from "@aws-sdk/protocol-http" ;
2+ import { HeaderBag } from "@aws-sdk/types" ;
23
34import { ALWAYS_UNSIGNABLE_HEADERS } from "./constants" ;
45import { getCanonicalHeaders } from "./getCanonicalHeaders" ;
@@ -49,6 +50,24 @@ describe("getCanonicalHeaders", () => {
4950 } ) ;
5051 } ) ;
5152
53+ it ( "should ignore headers with undefined values" , ( ) => {
54+ const headers : HeaderBag = {
55+ "x-amz-user-agent" : "aws-sdk-js-v3" ,
56+ host : "foo.us-east-1.amazonaws.com" ,
57+ } ;
58+
59+ ( headers . foo as any ) = undefined ;
60+ const request = new HttpRequest ( {
61+ method : "POST" ,
62+ protocol : "https:" ,
63+ path : "/" ,
64+ headers,
65+ hostname : "foo.us-east-1.amazonaws.com" ,
66+ } ) ;
67+
68+ expect ( getCanonicalHeaders ( request ) ) . toEqual ( headers ) ;
69+ } ) ;
70+
5271 it ( "should allow specifying custom unsignable headers" , ( ) => {
5372 const request = new HttpRequest ( {
5473 method : "POST" ,
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ export const getCanonicalHeaders = (
1212) : HeaderBag => {
1313 const canonical : HeaderBag = { } ;
1414 for ( const headerName of Object . keys ( headers ) . sort ( ) ) {
15+ if ( ! headers [ headerName ] ) {
16+ continue ;
17+ }
18+
1519 const canonicalHeaderName = headerName . toLowerCase ( ) ;
1620 if (
1721 canonicalHeaderName in ALWAYS_UNSIGNABLE_HEADERS ||
You can’t perform that action at this time.
0 commit comments