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 1
1
import { HttpRequest } from "@aws-sdk/protocol-http" ;
2
+ import { HeaderBag } from "@aws-sdk/types" ;
2
3
3
4
import { ALWAYS_UNSIGNABLE_HEADERS } from "./constants" ;
4
5
import { getCanonicalHeaders } from "./getCanonicalHeaders" ;
@@ -49,6 +50,24 @@ describe("getCanonicalHeaders", () => {
49
50
} ) ;
50
51
} ) ;
51
52
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
+
52
71
it ( "should allow specifying custom unsignable headers" , ( ) => {
53
72
const request = new HttpRequest ( {
54
73
method : "POST" ,
Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ export const getCanonicalHeaders = (
12
12
) : HeaderBag => {
13
13
const canonical : HeaderBag = { } ;
14
14
for ( const headerName of Object . keys ( headers ) . sort ( ) ) {
15
+ if ( ! headers [ headerName ] ) {
16
+ continue ;
17
+ }
18
+
15
19
const canonicalHeaderName = headerName . toLowerCase ( ) ;
16
20
if (
17
21
canonicalHeaderName in ALWAYS_UNSIGNABLE_HEADERS ||
You can’t perform that action at this time.
0 commit comments