File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
packages/middleware-content-length/src Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
11
11
} from "@aws-sdk/types" ;
12
12
13
13
const CONTENT_LENGTH_HEADER = "content-length" ;
14
+ const TRANSFER_ENCODING_HEADER = "transfer-encoding" ;
14
15
15
16
export function contentLengthMiddleware ( bodyLengthChecker : BodyLengthCalculator ) : BuildMiddleware < any , any > {
16
17
return < Output extends MetadataBearer > ( next : BuildHandler < any , Output > ) : BuildHandler < any , Output > =>
@@ -24,12 +25,17 @@ export function contentLengthMiddleware(bodyLengthChecker: BodyLengthCalculator)
24
25
. map ( ( str ) => str . toLowerCase ( ) )
25
26
. indexOf ( CONTENT_LENGTH_HEADER ) === - 1
26
27
) {
27
- const length = bodyLengthChecker ( body ) ;
28
- if ( length !== undefined ) {
28
+ try {
29
+ const length = bodyLengthChecker ( body ) ;
29
30
request . headers = {
30
31
...request . headers ,
31
32
[ CONTENT_LENGTH_HEADER ] : String ( length ) ,
32
33
} ;
34
+ } catch ( error ) {
35
+ request . headers = {
36
+ ...request . headers ,
37
+ [ TRANSFER_ENCODING_HEADER ] : "chunked" ,
38
+ } ;
33
39
}
34
40
}
35
41
}
You can’t perform that action at this time.
0 commit comments