File tree Expand file tree Collapse file tree 2 files changed +19
-16
lines changed
packages/middleware-content-length Expand file tree Collapse file tree 2 files changed +19
-16
lines changed Original file line number Diff line number Diff line change 14
14
},
15
15
"license" : " Apache-2.0" ,
16
16
"dependencies" : {
17
- "@aws-sdk/types" : " ^0.1.0-preview.7" ,
17
+ "@aws-sdk/types" : " ^0.1.0-preview.5" ,
18
+ "@aws-sdk/protocol-http" : " ^0.1.0-preview.1" ,
18
19
"tslib" : " ^1.8.0"
19
20
},
20
21
"devDependencies" : {
Original file line number Diff line number Diff line change 4
4
BuildMiddleware ,
5
5
BodyLengthCalculator ,
6
6
MetadataBearer ,
7
- BuildHandlerOutput ,
8
- HttpRequest
7
+ BuildHandlerOutput
9
8
} from "@aws-sdk/types" ;
9
+ import { HttpRequest } from "@aws-sdk/protocol-http" ;
10
10
11
11
export function contentLengthMiddleware (
12
12
bodyLengthCalculator : BodyLengthCalculator
@@ -18,19 +18,21 @@ export function contentLengthMiddleware(
18
18
) : Promise < BuildHandlerOutput < Output > > => {
19
19
let request = { ...args . request } ;
20
20
//TODO: cast request with instanceof
21
- const { body, headers } = < HttpRequest > request ;
22
- if (
23
- body &&
24
- Object . keys ( headers )
25
- . map ( str => str . toLowerCase ( ) )
26
- . indexOf ( "content-length" ) === - 1
27
- ) {
28
- const length = bodyLengthCalculator ( body ) ;
29
- if ( length !== undefined ) {
30
- ( < HttpRequest > request ) . headers = {
31
- ...( < HttpRequest > request ) . headers ,
32
- "Content-Length" : String ( length )
33
- } ;
21
+ if ( HttpRequest . isHttpRequest ( request ) ) {
22
+ const { body, headers } = request ;
23
+ if (
24
+ body &&
25
+ Object . keys ( headers )
26
+ . map ( str => str . toLowerCase ( ) )
27
+ . indexOf ( "content-length" ) === - 1
28
+ ) {
29
+ const length = bodyLengthCalculator ( body ) ;
30
+ if ( length !== undefined ) {
31
+ request . headers = {
32
+ ...request . headers ,
33
+ "Content-Length" : String ( length )
34
+ } ;
35
+ }
34
36
}
35
37
}
36
38
You can’t perform that action at this time.
0 commit comments