Explorar o código

Ensure S3 endpoint scheme; Trim all redundant slashes from S3 object key

DarthSim hai 1 ano
pai
achega
e703f6d4d0
Modificáronse 2 ficheiros con 8 adicións e 2 borrados
  1. 2 0
      CHANGELOG.md
  2. 6 2
      transport/s3/s3.go

+ 2 - 0
CHANGELOG.md

@@ -2,6 +2,8 @@
 
 
 ## [Unreleased]
 ## [Unreleased]
 ### Changed
 ### 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.
 - (pro) Allow specifying [gradient](https://docs.imgproxy.net/latest/usage/processing#gradient) direction as an angle in degrees.
 
 
 ### Fix
 ### Fix

+ 6 - 2
transport/s3/s3.go

@@ -73,8 +73,12 @@ func New() (http.RoundTripper, error) {
 	clientOptions := []func(*s3.Options){}
 	clientOptions := []func(*s3.Options){}
 
 
 	if len(config.S3Endpoint) != 0 {
 	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) {
 		clientOptions = append(clientOptions, func(o *s3.Options) {
-			o.BaseEndpoint = aws.String(config.S3Endpoint)
+			o.BaseEndpoint = aws.String(endpoint)
 			o.UsePathStyle = true
 			o.UsePathStyle = true
 		})
 		})
 	}
 	}
@@ -95,7 +99,7 @@ func New() (http.RoundTripper, error) {
 
 
 func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
 func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
 	bucket := req.URL.Host
 	bucket := req.URL.Host
-	key := strings.TrimPrefix(req.URL.Path, "/")
+	key := strings.TrimLeft(req.URL.Path, "/")
 
 
 	if len(bucket) == 0 || len(key) == 0 {
 	if len(bucket) == 0 || len(key) == 0 {
 		body := strings.NewReader("Invalid S3 URL: bucket name or object key is empty")
 		body := strings.NewReader("Invalid S3 URL: bucket name or object key is empty")