Viktor Sokolov 2 місяців тому
батько
коміт
c59ef97a2a
2 змінених файлів з 12 додано та 24 видалено
  1. 8 21
      imagedata/download.go
  2. 4 3
      imagedata/image_data_i.go

+ 8 - 21
imagedata/download.go

@@ -3,14 +3,12 @@ package imagedata
 import (
 	"context"
 	"net/http"
-	"slices"
 
 	"github.com/imgproxy/imgproxy/v3/config"
 	"github.com/imgproxy/imgproxy/v3/ierrors"
 	"github.com/imgproxy/imgproxy/v3/imagefetcher"
 	"github.com/imgproxy/imgproxy/v3/security"
 	"github.com/imgproxy/imgproxy/v3/transport"
-	"go.withmatt.com/httpheaders"
 )
 
 var (
@@ -18,18 +16,6 @@ var (
 
 	// For tests
 	redirectAllRequestsTo string
-
-	// keepResponseHeaders is a list of HTTP headers that should be preserved in the response
-	keepResponseHeaders = []string{
-		httpheaders.CacheControl,
-		httpheaders.Expires,
-		httpheaders.LastModified,
-		// NOTE:
-		// httpheaders.Etag == "Etag".
-		// Http header names are case-insensitive, but we rely on the case in most cases.
-		// We must migrate to http.Headers and the subsequent methods everywhere.
-		httpheaders.Etag,
-	}
 )
 
 type DownloadOptions struct {
@@ -86,15 +72,16 @@ func download(ctx context.Context, imageURL string, opts DownloadOptions, secopt
 
 	h := make(map[string]string)
 	for k := range res.Header {
-		if !slices.Contains(keepResponseHeaders, k) {
-			continue
-		}
+		value := res.Header.Get(k)
+		h[k] = value
 
-		// TODO: Fix Etag/ETag inconsistency
+		// This is temporary workaround, will be addressed in the subsequent PR
 		if k == "Etag" {
-			h["ETag"] = res.Header.Get(k)
-		} else {
-			h[k] = res.Header.Get(k)
+			h["ETag"] = value
+		}
+
+		if k == "ETag" {
+			h["Etag"] = value
 		}
 	}
 

+ 4 - 3
imagedatanew/image_data.go → imagedata/image_data_i.go

@@ -1,4 +1,4 @@
-package imagedatanew
+package imagedata
 
 import (
 	"io"
@@ -8,8 +8,9 @@ import (
 	"github.com/imgproxy/imgproxy/v3/imagetype"
 )
 
-// ImageData is an interface that defines methods for reading image data and metadata
-type ImageData interface {
+// NOTE: This is temporary naming, will be fixed in the subsequent PR
+// ImageDataI is an interface that defines methods for reading image data and metadata
+type ImageDataI interface {
 	io.Closer               // Close closes the image data and releases any resources held by it
 	Reader() io.ReadSeeker  // Reader returns a new ReadSeeker for the image data
 	Meta() imagemeta.Meta   // Meta returns the metadata of the image data