DarthSim 3 éve
szülő
commit
16c0d91d47
5 módosított fájl, 20 hozzáadás és 11 törlés
  1. 3 0
      CHANGELOG.md
  2. 3 0
      config/config.go
  3. 1 0
      docs/configuration.md
  4. 2 2
      etag/etag.go
  5. 11 9
      etag/etag_test.go

+ 3 - 0
CHANGELOG.md

@@ -1,6 +1,9 @@
 # Changelog
 
 ## [Unreleased]
+### Added
+- Add `IMGPROXY_ETAG_BUSTER` config.
+
 ### Change
 - Improved ICC profiles handling.
 - Proper error message when the deprecated basic URL format is used.

+ 3 - 0
config/config.go

@@ -90,6 +90,7 @@ var (
 	ABSEndpoint         string
 
 	ETagEnabled bool
+	ETagBuster  string
 
 	BaseURL string
 
@@ -226,6 +227,7 @@ func Reset() {
 	ABSEndpoint = ""
 
 	ETagEnabled = false
+	ETagBuster = ""
 
 	BaseURL = ""
 
@@ -371,6 +373,7 @@ func Configure() error {
 	configurators.String(&ABSEndpoint, "IMGPROXY_ABS_ENDPOINT")
 
 	configurators.Bool(&ETagEnabled, "IMGPROXY_USE_ETAG")
+	configurators.String(&ETagBuster, "IMGPROXY_ETAG_BUSTER")
 
 	configurators.String(&BaseURL, "IMGPROXY_BASE_URL")
 

+ 1 - 0
docs/configuration.md

@@ -41,6 +41,7 @@ echo $(xxd -g 2 -l 64 -p /dev/random | tr -d '\n')
 * `IMGPROXY_PATH_PREFIX`: URL path prefix. Example: when set to `/abc/def`, imgproxy URL will be `/abc/def/%signature/%processing_options/%source_url`. Default: blank.
 * `IMGPROXY_USER_AGENT`: User-Agent header that will be sent with source image request. Default: `imgproxy/%current_version`;
 * `IMGPROXY_USE_ETAG`: when `true`, enables using [ETag](https://en.wikipedia.org/wiki/HTTP_ETag) HTTP header for HTTP cache control. Default: false;
+* `IMGPROXY_ETAG_BUSTER`: change this to change ETags for all the images. Default: blank.
 * `IMGPROXY_CUSTOM_REQUEST_HEADERS`: <i class='badge badge-pro'></i> list of custom headers that imgproxy will send while requesting the source image, divided by `\;` (can be redefined by `IMGPROXY_CUSTOM_HEADERS_SEPARATOR`). Example: `X-MyHeader1=Lorem\;X-MyHeader2=Ipsum`;
 * `IMGPROXY_CUSTOM_RESPONSE_HEADERS`: <i class='badge badge-pro'></i> list of custom response headers, divided by `\;` (can be redefined by `IMGPROXY_CUSTOM_HEADERS_SEPARATOR`). Example: `X-MyHeader1=Lorem\;X-MyHeader2=Ipsum`;
 * `IMGPROXY_CUSTOM_HEADERS_SEPARATOR`: <i class='badge badge-pro'></i> string that will be used as a custom headers separator. Default: `\;`;

+ 2 - 2
etag/etag.go

@@ -10,9 +10,9 @@ import (
 	"strings"
 	"sync"
 
+	"github.com/imgproxy/imgproxy/v3/config"
 	"github.com/imgproxy/imgproxy/v3/imagedata"
 	"github.com/imgproxy/imgproxy/v3/options"
-	"github.com/imgproxy/imgproxy/v3/version"
 )
 
 type eTagCalc struct {
@@ -93,7 +93,7 @@ func (h *Handler) SetActualProcessingOptions(po *options.ProcessingOptions) bool
 	defer eTagCalcPool.Put(c)
 
 	c.hash.Reset()
-	c.hash.Write([]byte(version.Version()))
+	c.hash.Write([]byte(config.ETagBuster))
 	c.enc.Encode(po)
 
 	h.poHashActual = base64.RawURLEncoding.EncodeToString(c.hash.Sum(nil))

+ 11 - 9
etag/etag_test.go

@@ -6,6 +6,7 @@ import (
 	"strings"
 	"testing"
 
+	"github.com/imgproxy/imgproxy/v3/config"
 	"github.com/imgproxy/imgproxy/v3/imagedata"
 	"github.com/imgproxy/imgproxy/v3/options"
 	"github.com/sirupsen/logrus"
@@ -24,8 +25,8 @@ var (
 		Data: []byte("Hello Test"),
 	}
 
-	etagReq  string
-	etagData string
+	etagReq  = `"yj0WO6sFU4GCciYUBWjzvvfqrBh869doeOC2Pp5EI1Y/RImxvcmVtaXBzdW1kb2xvciI"`
+	etagData = `"yj0WO6sFU4GCciYUBWjzvvfqrBh869doeOC2Pp5EI1Y/DvyChhMNu_sFX7jrjoyrgQbnFwfoOVv7kzp_Fbs6hQBg"`
 )
 
 type EtagTestSuite struct {
@@ -36,13 +37,6 @@ type EtagTestSuite struct {
 
 func (s *EtagTestSuite) SetupSuite() {
 	logrus.SetOutput(ioutil.Discard)
-
-	s.h.SetActualProcessingOptions(po)
-	s.h.SetActualImageData(&imgWithETag)
-	etagReq = s.h.GenerateActualETag()
-
-	s.h.SetActualImageData(&imgWithoutETag)
-	etagData = s.h.GenerateActualETag()
 }
 
 func (s *EtagTestSuite) TeardownSuite() {
@@ -51,6 +45,7 @@ func (s *EtagTestSuite) TeardownSuite() {
 
 func (s *EtagTestSuite) SetupTest() {
 	s.h = Handler{}
+	config.Reset()
 }
 
 func (s *EtagTestSuite) TestGenerateActualReq() {
@@ -137,6 +132,13 @@ func (s *EtagTestSuite) TestImageDataCheckReqToDataFailure() {
 	assert.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
 }
 
+func (s *EtagTestSuite) TestETagBusterFailure() {
+	config.ETagBuster = "busted"
+
+	s.h.ParseExpectedETag(etagReq)
+	assert.False(s.T(), s.h.SetActualImageData(&imgWithoutETag))
+}
+
 func TestEtag(t *testing.T) {
 	suite.Run(t, new(EtagTestSuite))
 }