mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-02-12 11:46:10 +02:00
Ensure S3 endpoint scheme; Trim all redundant slashes from S3 object key
This commit is contained in:
parent
a23737a90b
commit
e703f6d4d0
@ -2,6 +2,8 @@
|
||||
|
||||
## [Unreleased]
|
||||
### Changed
|
||||
- Automatically add `http://` scheme to the `IMGPROXY_S3_ENDPOINT` value if it has no scheme.
|
||||
- Trim redundant slashes in the S3 object key.
|
||||
- (pro) Allow specifying [gradient](https://docs.imgproxy.net/latest/usage/processing#gradient) direction as an angle in degrees.
|
||||
|
||||
### Fix
|
||||
|
@ -73,8 +73,12 @@ func New() (http.RoundTripper, error) {
|
||||
clientOptions := []func(*s3.Options){}
|
||||
|
||||
if len(config.S3Endpoint) != 0 {
|
||||
endpoint := config.S3Endpoint
|
||||
if !strings.HasPrefix(endpoint, "http://") && !strings.HasPrefix(endpoint, "https://") {
|
||||
endpoint = "http://" + endpoint
|
||||
}
|
||||
clientOptions = append(clientOptions, func(o *s3.Options) {
|
||||
o.BaseEndpoint = aws.String(config.S3Endpoint)
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
o.UsePathStyle = true
|
||||
})
|
||||
}
|
||||
@ -95,7 +99,7 @@ func New() (http.RoundTripper, error) {
|
||||
|
||||
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
bucket := req.URL.Host
|
||||
key := strings.TrimPrefix(req.URL.Path, "/")
|
||||
key := strings.TrimLeft(req.URL.Path, "/")
|
||||
|
||||
if len(bucket) == 0 || len(key) == 0 {
|
||||
body := strings.NewReader("Invalid S3 URL: bucket name or object key is empty")
|
||||
|
Loading…
x
Reference in New Issue
Block a user