Skip to content

Commit 6968cf3

Browse files
committed
Merge remote-tracking branch 'lin/feature-virtual-host' into fork
2 parents 54d6a8a + 7e97a9a commit 6968cf3

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

command/app.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ var app = &cli.App{
9090
Name: "credentials-file",
9191
Usage: "use the specified credentials file instead of the default credentials file",
9292
},
93+
&cli.GenericFlag{
94+
Name: "addressing-style",
95+
Usage: "use virtual host style or path style endpoint: (path, virtual)",
96+
Value: &EnumValue{
97+
Enum: []string{"path", "virtual"},
98+
Default: "path",
99+
},
100+
EnvVars: []string{"S3_ADDRESSING_STYLE"},
101+
},
93102
},
94103
Before: func(c *cli.Context) error {
95104
retryCount := c.Int("retry-count")
@@ -190,6 +199,7 @@ func NewStorageOpts(c *cli.Context) storage.Options {
190199
CredentialFile: c.String("credentials-file"),
191200
LogLevel: log.LevelFromString(c.String("log")),
192201
NoSuchUploadRetryCount: c.Int("no-such-upload-retry-count"),
202+
AddressingStyle: c.String("addressing-style"),
193203
}
194204
}
195205

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
func main() {
1313
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
1414
defer cancel()
15-
1615
if err := command.Main(ctx, os.Args); err != nil {
1716
os.Exit(1)
1817
}

storage/s3.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const (
5050

5151
// the key of the object metadata which is used to handle retry decision on NoSuchUpload error
5252
metadataKeyRetryID = "s5cmd-upload-retry-id"
53+
54+
AddressingVirtualHostStyle = "virtual"
5355
)
5456

5557
// Re-used AWS sessions dramatically improve performance.
@@ -1255,7 +1257,7 @@ func (sc *SessionCache) newSession(ctx context.Context, opts Options) (*session.
12551257

12561258
// use virtual-host-style if the endpoint is known to support it,
12571259
// otherwise use the path-style approach.
1258-
isVirtualHostStyle := isVirtualHostStyle(endpointURL)
1260+
isVirtualHostStyle := isVirtualHostStyle(endpointURL, opts.AddressingStyle)
12591261

12601262
useAccelerate := supportsTransferAcceleration(endpointURL)
12611263
// AWS SDK handles transfer acceleration automatically. Setting the
@@ -1422,11 +1424,18 @@ func IsGoogleEndpoint(endpoint urlpkg.URL) bool {
14221424
return endpoint.Hostname() == gcsEndpoint
14231425
}
14241426

1427+
func ForcedVirtualHostStyle(endpoint urlpkg.URL, addressingStyle string) bool {
1428+
return addressingStyle == AddressingVirtualHostStyle
1429+
}
1430+
14251431
// isVirtualHostStyle reports whether the given endpoint supports S3 virtual
14261432
// host style bucket name resolving. If a custom S3 API compatible endpoint is
14271433
// given, resolve the bucketname from the URL path.
1428-
func isVirtualHostStyle(endpoint urlpkg.URL) bool {
1429-
return endpoint == sentinelURL || supportsTransferAcceleration(endpoint) || IsGoogleEndpoint(endpoint)
1434+
func isVirtualHostStyle(endpoint urlpkg.URL, addressingStyle string) bool {
1435+
return endpoint == sentinelURL ||
1436+
supportsTransferAcceleration(endpoint) ||
1437+
IsGoogleEndpoint(endpoint) ||
1438+
ForcedVirtualHostStyle(endpoint, addressingStyle)
14301439
}
14311440

14321441
func errHasCode(err error, code string) bool {

storage/storage.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func NewRemoteClient(ctx context.Context, url *url.URL, opts Options) (*S3, erro
7171
LogLevel: opts.LogLevel,
7272
bucket: url.Bucket,
7373
region: opts.region,
74+
AddressingStyle: opts.AddressingStyle,
7475
}
7576
return newS3Storage(ctx, newOpts)
7677
}
@@ -97,6 +98,7 @@ type Options struct {
9798
CredentialFile string
9899
bucket string
99100
region string
101+
AddressingStyle string
100102
}
101103

102104
func (o *Options) SetRegion(region string) {

0 commit comments

Comments
 (0)