@@ -13,37 +13,37 @@ import {
1313
1414import { Md5BodyChecksumResolvedConfig } from "./md5Configuration" ;
1515
16- export function applyMd5BodyChecksumMiddleware ( options : Md5BodyChecksumResolvedConfig ) : BuildMiddleware < any , any > {
17- return < Output extends MetadataBearer > ( next : BuildHandler < any , Output > ) : BuildHandler < any , Output > =>
18- async ( args : BuildHandlerArguments < any > ) : Promise < BuildHandlerOutput < Output > > => {
19- let { request } = args ;
20- if ( HttpRequest . isInstance ( request ) ) {
21- const { body, headers } = request ;
22- if ( ! hasHeader ( "Content-MD5" , headers ) ) {
23- let digest : Promise < Uint8Array > ;
24- if ( body === undefined || typeof body === "string" || ArrayBuffer . isView ( body ) || isArrayBuffer ( body ) ) {
25- const hash = new options . md5 ( ) ;
26- hash . update ( body || "" ) ;
27- digest = hash . digest ( ) ;
28- } else {
29- digest = options . streamHasher ( options . md5 , body ) ;
30- }
31-
32- request = {
33- ...request ,
34- headers : {
35- ...headers ,
36- "Content-MD5" : options . base64Encoder ( await digest ) ,
37- } ,
38- } ;
16+ export const applyMd5BodyChecksumMiddleware =
17+ ( options : Md5BodyChecksumResolvedConfig ) : BuildMiddleware < any , any > =>
18+ < Output extends MetadataBearer > ( next : BuildHandler < any , Output > ) : BuildHandler < any , Output > =>
19+ async ( args : BuildHandlerArguments < any > ) : Promise < BuildHandlerOutput < Output > > => {
20+ let { request } = args ;
21+ if ( HttpRequest . isInstance ( request ) ) {
22+ const { body, headers } = request ;
23+ if ( ! hasHeader ( "Content-MD5" , headers ) ) {
24+ let digest : Promise < Uint8Array > ;
25+ if ( body === undefined || typeof body === "string" || ArrayBuffer . isView ( body ) || isArrayBuffer ( body ) ) {
26+ const hash = new options . md5 ( ) ;
27+ hash . update ( body || "" ) ;
28+ digest = hash . digest ( ) ;
29+ } else {
30+ digest = options . streamHasher ( options . md5 , body ) ;
3931 }
32+
33+ request = {
34+ ...request ,
35+ headers : {
36+ ...headers ,
37+ "Content-MD5" : options . base64Encoder ( await digest ) ,
38+ } ,
39+ } ;
4040 }
41- return next ( {
42- ... args ,
43- request ,
44- } ) ;
45- } ;
46- }
41+ }
42+ return next ( {
43+ ... args ,
44+ request ,
45+ } ) ;
46+ } ;
4747
4848export const applyMd5BodyChecksumMiddlewareOptions : BuildHandlerOptions = {
4949 name : "applyMd5BodyChecksumMiddleware" ,
@@ -58,7 +58,7 @@ export const getApplyMd5BodyChecksumPlugin = (config: Md5BodyChecksumResolvedCon
5858 } ,
5959} ) ;
6060
61- function hasHeader ( soughtHeader : string , headers : HeaderBag ) : boolean {
61+ const hasHeader = ( soughtHeader : string , headers : HeaderBag ) : boolean => {
6262 soughtHeader = soughtHeader . toLowerCase ( ) ;
6363 for ( const headerName of Object . keys ( headers ) ) {
6464 if ( soughtHeader === headerName . toLowerCase ( ) ) {
@@ -67,4 +67,4 @@ function hasHeader(soughtHeader: string, headers: HeaderBag): boolean {
6767 }
6868
6969 return false ;
70- }
70+ } ;
0 commit comments