Quellcode durchsuchen

Rename `IMGPROXY_ENABLE_*_DETECTION` configs to `IMGPROXY_AUTO_*`

DarthSim vor 4 Monaten
Ursprung
Commit
90e5f19a6e
5 geänderte Dateien mit 36 neuen und 19 gelöschten Zeilen
  1. 9 1
      CHANGELOG.md
  2. 22 13
      config/config.go
  3. 3 3
      options/processing_options.go
  4. 1 1
      options/processing_options_test.go
  5. 1 1
      processing_handler.go

+ 9 - 1
CHANGELOG.md

@@ -3,10 +3,14 @@
 ## [Unreleased]
 ### Add
 - Add JPEL XL (JXL) support.
-- Add [IMGPROXY_ENABLE_JXL_DETECTION](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_ENABLE_JXL_DETECTION), [IMGPROXY_ENFORCE_JXL](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_ENFORCE_JXL), and [IMGPROXY_JXL_EFFORT](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_JXL_EFFORT) configs.
+- Add [IMGPROXY_AUTO_JXL](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_AUTO_JXL), [IMGPROXY_ENFORCE_JXL](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_ENFORCE_JXL), and [IMGPROXY_JXL_EFFORT](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_JXL_EFFORT) configs.
 - (pro) Add [objects_position](https://docs.imgproxy.net/latest/usage/processing#objects-position) processing and info options.
 - (pro) Add [IMGPROXY_OBJECT_DETECTION_SWAP_RB](https://docs.imgproxy.net/latest/configuration/options#IMGPROXY_OBJECT_DETECTION_SWAP_RB) config.
 
+### Changed
+- Rename `IMGPROXY_ENABLE_WEBP_DETECTION` to `IMGPROXY_AUTO_WEBP`. The old name is deprecated but still supported.
+- Rename `IMGPROXY_ENABLE_AVIF_DETECTION` to `IMGPROXY_AUTO_AVIF`. The old name is deprecated but still supported.
+
 ### Fixed
 - Fix detecting of width and height of HEIF images that include `irot` boxes.
 - Set `Error` status for errorred traces in OpenTelemetry.
@@ -16,6 +20,10 @@
 - (pro) Fix detecting of width and height when orientation is specified in EXIF but EXIF info is not requested.
 - (pro) Fix watermark shadow clipping.
 
+### Deprecated
+- `IMGPROXY_ENABLE_WEBP_DETECTION` config is deprecated. Use `IMGPROXY_AUTO_WEBP` instead.
+- `IMGPROXY_ENABLE_AVIF_DETECTION` config is deprecated. Use `IMGPROXY_AUTO_AVIF` instead.
+
 ## [3.26.1] - 2024-10-28
 ### Changed
 - (pro) Improve `monochrome` and `duotone` processing options.

+ 22 - 13
config/config.go

@@ -65,13 +65,13 @@ var (
 	ReturnAttachment      bool
 	SvgFixUnsupported     bool
 
-	EnableWebpDetection bool
-	EnforceWebp         bool
-	EnableAvifDetection bool
-	EnforceAvif         bool
-	EnableJxlDetection  bool
-	EnforceJxl          bool
-	EnableClientHints   bool
+	AutoWebp          bool
+	EnforceWebp       bool
+	AutoAvif          bool
+	EnforceAvif       bool
+	AutoJxl           bool
+	EnforceJxl        bool
+	EnableClientHints bool
 
 	PreferredFormats []imagetype.Type
 
@@ -267,11 +267,11 @@ func Reset() {
 	ReturnAttachment = false
 	SvgFixUnsupported = false
 
-	EnableWebpDetection = false
+	AutoWebp = false
 	EnforceWebp = false
-	EnableAvifDetection = false
+	AutoAvif = false
 	EnforceAvif = false
-	EnableJxlDetection = false
+	AutoJxl = false
 	EnforceJxl = false
 	EnableClientHints = false
 
@@ -494,11 +494,20 @@ func Configure() error {
 	configurators.Bool(&ReturnAttachment, "IMGPROXY_RETURN_ATTACHMENT")
 	configurators.Bool(&SvgFixUnsupported, "IMGPROXY_SVG_FIX_UNSUPPORTED")
 
-	configurators.Bool(&EnableWebpDetection, "IMGPROXY_ENABLE_WEBP_DETECTION")
+	if _, ok := os.LookupEnv("IMGPROXY_ENABLE_WEBP_DETECTION"); ok {
+		log.Warning("IMGPROXY_ENABLE_WEBP_DETECTION is deprecated, use IMGPROXY_AUTO_WEBP instead")
+		configurators.Bool(&AutoWebp, "IMGPROXY_ENABLE_WEBP_DETECTION")
+	}
+	if _, ok := os.LookupEnv("IMGPROXY_ENABLE_AVIF_DETECTION"); ok {
+		log.Warning("IMGPROXY_ENABLE_AVIF_DETECTION is deprecated, use IMGPROXY_AUTO_AVIF instead")
+		configurators.Bool(&AutoAvif, "IMGPROXY_ENABLE_AVIF_DETECTION")
+	}
+
+	configurators.Bool(&AutoWebp, "IMGPROXY_AUTO_WEBP")
 	configurators.Bool(&EnforceWebp, "IMGPROXY_ENFORCE_WEBP")
-	configurators.Bool(&EnableAvifDetection, "IMGPROXY_ENABLE_AVIF_DETECTION")
+	configurators.Bool(&AutoAvif, "IMGPROXY_AUTO_AVIF")
 	configurators.Bool(&EnforceAvif, "IMGPROXY_ENFORCE_AVIF")
-	configurators.Bool(&EnableJxlDetection, "IMGPROXY_ENABLE_JXL_DETECTION")
+	configurators.Bool(&AutoJxl, "IMGPROXY_AUTO_JXL")
 	configurators.Bool(&EnforceJxl, "IMGPROXY_ENFORCE_JXL")
 	configurators.Bool(&EnableClientHints, "IMGPROXY_ENABLE_CLIENT_HINTS")
 

+ 3 - 3
options/processing_options.go

@@ -1081,17 +1081,17 @@ func defaultProcessingOptions(headers http.Header) (*ProcessingOptions, error) {
 	headerAccept := headers.Get("Accept")
 
 	if strings.Contains(headerAccept, "image/webp") {
-		po.PreferWebP = config.EnableWebpDetection || config.EnforceWebp
+		po.PreferWebP = config.AutoWebp || config.EnforceWebp
 		po.EnforceWebP = config.EnforceWebp
 	}
 
 	if strings.Contains(headerAccept, "image/avif") {
-		po.PreferAvif = config.EnableAvifDetection || config.EnforceAvif
+		po.PreferAvif = config.AutoAvif || config.EnforceAvif
 		po.EnforceAvif = config.EnforceAvif
 	}
 
 	if strings.Contains(headerAccept, "image/jxl") {
-		po.PreferJxl = config.EnableJxlDetection || config.EnforceJxl
+		po.PreferJxl = config.AutoJxl || config.EnforceJxl
 		po.EnforceJxl = config.EnforceJxl
 	}
 

+ 1 - 1
options/processing_options_test.go

@@ -478,7 +478,7 @@ func (s *ProcessingOptionsTestSuite) TestParsePathStripMetadata() {
 }
 
 func (s *ProcessingOptionsTestSuite) TestParsePathWebpDetection() {
-	config.EnableWebpDetection = true
+	config.AutoWebp = true
 
 	path := "/plain/http://images.dev/lorem/ipsum.jpg"
 	headers := http.Header{"Accept": []string{"image/webp"}}

+ 1 - 1
processing_handler.go

@@ -46,7 +46,7 @@ func initProcessingHandler() {
 
 	vary := make([]string, 0)
 
-	if config.EnableWebpDetection || config.EnforceWebp || config.EnableAvifDetection || config.EnforceAvif {
+	if config.AutoWebp || config.EnforceWebp || config.AutoAvif || config.EnforceAvif {
 		vary = append(vary, "Accept")
 	}