@@ -15,76 +15,84 @@ import { bucketHostname } from "./bucketHostname";
15
15
import { getPseudoRegion } from "./bucketHostnameUtils" ;
16
16
import { BucketEndpointResolvedConfig } from "./configurations" ;
17
17
18
- export const bucketEndpointMiddleware = ( options : BucketEndpointResolvedConfig ) : BuildMiddleware < any , any > => <
19
- Output extends MetadataBearer
20
- > (
21
- next : BuildHandler < any , Output > ,
22
- context : HandlerExecutionContext
23
- ) : BuildHandler < any , Output > => async ( args : BuildHandlerArguments < any > ) : Promise < BuildHandlerOutput < Output > > => {
24
- const { Bucket : bucketName } = args . input as { Bucket : string } ;
25
- let replaceBucketInPath = options . bucketEndpoint ;
26
- const request = args . request ;
27
- if ( HttpRequest . isInstance ( request ) ) {
28
- if ( options . bucketEndpoint ) {
29
- request . hostname = bucketName ;
30
- } else if ( validateArn ( bucketName ) ) {
31
- const bucketArn = parseArn ( bucketName ) ;
32
- const clientRegion = getPseudoRegion ( await options . region ( ) ) ;
33
- const { partition, signingRegion = clientRegion } = ( await options . regionInfoProvider ( clientRegion ) ) || { } ;
34
- const useArnRegion = await options . useArnRegion ( ) ;
35
- const { hostname, bucketEndpoint, signingRegion : modifiedSigningRegion , signingService } = bucketHostname ( {
36
- bucketName : bucketArn ,
37
- baseHostname : request . hostname ,
38
- accelerateEndpoint : options . useAccelerateEndpoint ,
39
- dualstackEndpoint : options . useDualstackEndpoint ,
40
- pathStyleEndpoint : options . forcePathStyle ,
41
- tlsCompatible : request . protocol === "https:" ,
42
- useArnRegion,
43
- clientPartition : partition ,
44
- clientSigningRegion : signingRegion ,
45
- clientRegion : clientRegion ,
46
- isCustomEndpoint : options . isCustomEndpoint ,
47
- disableMultiregionAccessPoints : await options . disableMultiregionAccessPoints ( ) ,
48
- } ) ;
18
+ export const bucketEndpointMiddleware =
19
+ ( options : BucketEndpointResolvedConfig ) : BuildMiddleware < any , any > =>
20
+ < Output extends MetadataBearer > (
21
+ next : BuildHandler < any , Output > ,
22
+ context : HandlerExecutionContext
23
+ ) : BuildHandler < any , Output > =>
24
+ async ( args : BuildHandlerArguments < any > ) : Promise < BuildHandlerOutput < Output > > => {
25
+ const { Bucket : bucketName } = args . input as { Bucket : string } ;
26
+ let replaceBucketInPath = options . bucketEndpoint ;
27
+ const request = args . request ;
28
+ if ( HttpRequest . isInstance ( request ) ) {
29
+ if ( options . bucketEndpoint ) {
30
+ request . hostname = bucketName ;
31
+ } else if ( validateArn ( bucketName ) ) {
32
+ const bucketArn = parseArn ( bucketName ) ;
33
+ const clientRegion = getPseudoRegion ( await options . region ( ) ) ;
34
+ const { partition, signingRegion = clientRegion } = ( await options . regionInfoProvider ( clientRegion ) ) || { } ;
35
+ const useArnRegion = await options . useArnRegion ( ) ;
36
+ const dualstackEndpoint = await options . useDualstackEndpoint ( ) ;
37
+ const {
38
+ hostname,
39
+ bucketEndpoint,
40
+ signingRegion : modifiedSigningRegion ,
41
+ signingService,
42
+ } = bucketHostname ( {
43
+ bucketName : bucketArn ,
44
+ baseHostname : request . hostname ,
45
+ accelerateEndpoint : options . useAccelerateEndpoint ,
46
+ dualstackEndpoint,
47
+ pathStyleEndpoint : options . forcePathStyle ,
48
+ tlsCompatible : request . protocol === "https:" ,
49
+ useArnRegion,
50
+ clientPartition : partition ,
51
+ clientSigningRegion : signingRegion ,
52
+ clientRegion : clientRegion ,
53
+ isCustomEndpoint : options . isCustomEndpoint ,
54
+ disableMultiregionAccessPoints : await options . disableMultiregionAccessPoints ( ) ,
55
+ } ) ;
49
56
50
- // If the request needs to use a region or service name inferred from ARN that different from client region, we
51
- // need to set them in the handler context so the signer will use them
52
- if ( modifiedSigningRegion && modifiedSigningRegion !== signingRegion ) {
53
- context [ "signing_region" ] = modifiedSigningRegion ;
54
- }
55
- if ( signingService && signingService !== "s3" ) {
56
- context [ "signing_service" ] = signingService ;
57
- }
57
+ // If the request needs to use a region or service name inferred from ARN that different from client region, we
58
+ // need to set them in the handler context so the signer will use them
59
+ if ( modifiedSigningRegion && modifiedSigningRegion !== signingRegion ) {
60
+ context [ "signing_region" ] = modifiedSigningRegion ;
61
+ }
62
+ if ( signingService && signingService !== "s3" ) {
63
+ context [ "signing_service" ] = signingService ;
64
+ }
58
65
59
- request . hostname = hostname ;
60
- replaceBucketInPath = bucketEndpoint ;
61
- } else {
62
- const clientRegion = getPseudoRegion ( await options . region ( ) ) ;
63
- const { hostname, bucketEndpoint } = bucketHostname ( {
64
- bucketName,
65
- clientRegion,
66
- baseHostname : request . hostname ,
67
- accelerateEndpoint : options . useAccelerateEndpoint ,
68
- dualstackEndpoint : options . useDualstackEndpoint ,
69
- pathStyleEndpoint : options . forcePathStyle ,
70
- tlsCompatible : request . protocol === "https:" ,
71
- isCustomEndpoint : options . isCustomEndpoint ,
72
- } ) ;
66
+ request . hostname = hostname ;
67
+ replaceBucketInPath = bucketEndpoint ;
68
+ } else {
69
+ const clientRegion = getPseudoRegion ( await options . region ( ) ) ;
70
+ const dualstackEndpoint = await options . useDualstackEndpoint ( ) ;
71
+ const { hostname, bucketEndpoint } = bucketHostname ( {
72
+ bucketName,
73
+ clientRegion,
74
+ baseHostname : request . hostname ,
75
+ accelerateEndpoint : options . useAccelerateEndpoint ,
76
+ dualstackEndpoint,
77
+ pathStyleEndpoint : options . forcePathStyle ,
78
+ tlsCompatible : request . protocol === "https:" ,
79
+ isCustomEndpoint : options . isCustomEndpoint ,
80
+ } ) ;
73
81
74
- request . hostname = hostname ;
75
- replaceBucketInPath = bucketEndpoint ;
76
- }
82
+ request . hostname = hostname ;
83
+ replaceBucketInPath = bucketEndpoint ;
84
+ }
77
85
78
- if ( replaceBucketInPath ) {
79
- request . path = request . path . replace ( / ^ ( \/ ) ? [ ^ \/ ] + / , "" ) ;
80
- if ( request . path === "" ) {
81
- request . path = "/" ;
86
+ if ( replaceBucketInPath ) {
87
+ request . path = request . path . replace ( / ^ ( \/ ) ? [ ^ \/ ] + / , "" ) ;
88
+ if ( request . path === "" ) {
89
+ request . path = "/" ;
90
+ }
82
91
}
83
92
}
84
- }
85
93
86
- return next ( { ...args , request } ) ;
87
- } ;
94
+ return next ( { ...args , request } ) ;
95
+ } ;
88
96
89
97
export const bucketEndpointMiddlewareOptions : RelativeMiddlewareOptions = {
90
98
tags : [ "BUCKET_ENDPOINT" ] ,
0 commit comments