@@ -15,76 +15,81 @@ 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 {
37
+ hostname,
38
+ bucketEndpoint,
39
+ signingRegion : modifiedSigningRegion ,
40
+ signingService,
41
+ } = bucketHostname ( {
42
+ bucketName : bucketArn ,
43
+ baseHostname : request . hostname ,
44
+ accelerateEndpoint : options . useAccelerateEndpoint ,
45
+ dualstackEndpoint : options . useDualstackEndpoint ,
46
+ pathStyleEndpoint : options . forcePathStyle ,
47
+ tlsCompatible : request . protocol === "https:" ,
48
+ useArnRegion,
49
+ clientPartition : partition ,
50
+ clientSigningRegion : signingRegion ,
51
+ clientRegion : clientRegion ,
52
+ isCustomEndpoint : options . isCustomEndpoint ,
53
+ } ) ;
49
54
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
- }
55
+ // If the request needs to use a region or service name inferred from ARN that different from client region, we
56
+ // need to set them in the handler context so the signer will use them
57
+ if ( modifiedSigningRegion && modifiedSigningRegion !== signingRegion ) {
58
+ context [ "signing_region" ] = modifiedSigningRegion ;
59
+ }
60
+ if ( signingService && signingService !== "s3" ) {
61
+ context [ "signing_service" ] = signingService ;
62
+ }
58
63
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
- } ) ;
64
+ request . hostname = hostname ;
65
+ replaceBucketInPath = bucketEndpoint ;
66
+ } else {
67
+ const clientRegion = getPseudoRegion ( await options . region ( ) ) ;
68
+ const { hostname, bucketEndpoint } = bucketHostname ( {
69
+ bucketName,
70
+ clientRegion,
71
+ baseHostname : request . hostname ,
72
+ accelerateEndpoint : options . useAccelerateEndpoint ,
73
+ dualstackEndpoint : options . useDualstackEndpoint ,
74
+ pathStyleEndpoint : options . forcePathStyle ,
75
+ tlsCompatible : request . protocol === "https:" ,
76
+ isCustomEndpoint : options . isCustomEndpoint ,
77
+ } ) ;
73
78
74
- request . hostname = hostname ;
75
- replaceBucketInPath = bucketEndpoint ;
76
- }
79
+ request . hostname = hostname ;
80
+ replaceBucketInPath = bucketEndpoint ;
81
+ }
77
82
78
- if ( replaceBucketInPath ) {
79
- request . path = request . path . replace ( / ^ ( \/ ) ? [ ^ \/ ] + / , "" ) ;
80
- if ( request . path === "" ) {
81
- request . path = "/" ;
83
+ if ( replaceBucketInPath ) {
84
+ request . path = request . path . replace ( / ^ ( \/ ) ? [ ^ \/ ] + / , "" ) ;
85
+ if ( request . path === "" ) {
86
+ request . path = "/" ;
87
+ }
82
88
}
83
89
}
84
- }
85
90
86
- return next ( { ...args , request } ) ;
87
- } ;
91
+ return next ( { ...args , request } ) ;
92
+ } ;
88
93
89
94
export const bucketEndpointMiddlewareOptions : RelativeMiddlewareOptions = {
90
95
tags : [ "BUCKET_ENDPOINT" ] ,
0 commit comments