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 {
1111} from "@aws-sdk/types" ;
1212
1313const CONTENT_LENGTH_HEADER = "content-length" ;
14+ const TRANSFER_ENCODING_HEADER = "transfer-encoding" ;
1415
1516export function contentLengthMiddleware ( bodyLengthChecker : BodyLengthCalculator ) : BuildMiddleware < any , any > {
1617 return < Output extends MetadataBearer > ( next : BuildHandler < any , Output > ) : BuildHandler < any , Output > =>
@@ -24,12 +25,17 @@ export function contentLengthMiddleware(bodyLengthChecker: BodyLengthCalculator)
2425 . map ( ( str ) => str . toLowerCase ( ) )
2526 . indexOf ( CONTENT_LENGTH_HEADER ) === - 1
2627 ) {
27- const length = bodyLengthChecker ( body ) ;
28- if ( length !== undefined ) {
28+ try {
29+ const length = bodyLengthChecker ( body ) ;
2930 request . headers = {
3031 ...request . headers ,
3132 [ CONTENT_LENGTH_HEADER ] : String ( length ) ,
3233 } ;
34+ } catch ( error ) {
35+ request . headers = {
36+ ...request . headers ,
37+ [ TRANSFER_ENCODING_HEADER ] : "chunked" ,
38+ } ;
3339 }
3440 }
3541 }
You can’t perform that action at this time.
0 commit comments