You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
S3 has two endpoints, a “path-based” endpoint and “virtual-hosted-style”
endpoints. ([read
more](https://medium.com/@e.osama85/the-difference-between-the-amazon-s3-path-style-urls-and-virtual-hosted-style-urls-4fafd5eca4db))
Virtual hosted style uses a different hostname for each bucket, while
path-style uses one endpoint and puts the bucket name in the path.
Path-style is easier to set up when using an S3-compatible API like
minio, because you don't have to deal with DNS certs etc.
Previously, we only used path-style if the URL was set to `localhost`,
which was basically only useful for our tests that ran `minio` locally.
This change allows the use of path-style URLs by setting the
`AWS_S3_USE_PATH_STYLE` env variable. It also supports the old
`localhost` behavior, but warns and suggests using
`AWS_S3_USE_PATH_STYLE`.
## `bucket_prefix` bug fix
This also fixes a bug where `Some("")` was being used as a
`bucket_prefix`. When a bucket prefix is a `Some`, we prepend it to the
path separated by "/", as in "{bucket_prefix}/{path}". With an empty
`bucket_prefix`, the resulting path is an "absolute-path" (since it
begins with a slash) instead of a "relative path" as the rest of the
code expects.
In particular, `Url::join` behaves very differently when passed an
"absolute path" than a relative one: with an absolute path, the new path
_replaces_ the whole other old one.
So what was happening was that when we had a `bucket_prefix` of `/`, if
the bucket name was in the path (as in path-style URLs), the bucket name
was inadvertently removed from the path.
The fix is as simple as ensuring that `Some("")` is converted to `None`,
as in:
```rust
let bucket_prefix = (!bucket_prefix.is_empty()).then(|| bucket_prefix);
```
let endpoint:Url = config.endpoint.parse().expect("endpoint is a valid url");
41
-
let path_style =
42
-
// if endpoint is localhost then bucket url must be of form http://localhost:<port>/<bucket>
43
-
// instead of <method>:://<bucket>.<endpoint>
44
-
if endpoint.host_str().expect("endpoint Url should have host") == "localhost"{
45
-
rusty_s3::UrlStyle::Path
46
-
}else{
47
-
rusty_s3::UrlStyle::VirtualHost
48
-
};
44
+
45
+
let path_style = if config.path_style{
46
+
rusty_s3::UrlStyle::Path
47
+
}elseif endpoint.host_str() == Some("localhost"){
48
+
// Since this was the old behavior before we added AWS_S3_USE_PATH_STYLE,
49
+
// we continue to support it, but complain a bit.
50
+
tracing::warn!("Inferring path-style URLs for localhost for backwards-compatibility. This behavior may change in the future. Set AWS_S3_USE_PATH_STYLE=true to ensure that path-style URLs are used.");
51
+
rusty_s3::UrlStyle::Path
52
+
}else{
53
+
rusty_s3::UrlStyle::VirtualHost
54
+
};
55
+
49
56
let bucket = Bucket::new(endpoint, path_style, config.bucket, config.region)
0 commit comments