فهرست منبع

Respond with original 4xx status on 4xx image response; Respond with 502 on 5xx image response

DarthSim 3 ماه پیش
والد
کامیت
5257a0e7cf
3فایلهای تغییر یافته به همراه11 افزوده شده و 4 حذف شده
  1. 5 0
      CHANGELOG.md
  2. 4 2
      imagedata/errors.go
  3. 2 2
      imagedata/image_data_test.go

+ 5 - 0
CHANGELOG.md

@@ -1,5 +1,10 @@
 # Changelog
 
+## [Unreleased]
+### Changed
+- When image source responds with a 4xx status code, imgproxy now responds with the same status code instead of always responding with `404 Not Found`.
+- When image source responds with a 5xx status code, imgproxy now responds with `502 Bad Gateway` instead of `500 Internal Server Error`.
+
 ## [3.30.1] - 2025-10-10
 ### Changed
 - Format New Relic and OpenTelemetry metadata values that implement the `fmt.Stringer` interface as strings.

+ 4 - 2
imagedata/errors.go

@@ -76,8 +76,10 @@ func newImageResponseStatusError(status int, body string) error {
 	}
 
 	statusCode := 404
-	if status >= 500 {
-		statusCode = 500
+	if status >= 400 && status < 500 {
+		statusCode = status
+	} else if status >= 500 {
+		statusCode = http.StatusBadGateway
 	}
 
 	return ierrors.Wrap(

+ 2 - 2
imagedata/image_data_test.go

@@ -192,7 +192,7 @@ func (s *ImageDataTestSuite) TestDownloadStatusForbidden() {
 	imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
 
 	s.Require().Error(err)
-	s.Require().Equal(404, ierrors.Wrap(err, 0).StatusCode())
+	s.Require().Equal(403, ierrors.Wrap(err, 0).StatusCode())
 	s.Require().Nil(imgdata)
 }
 
@@ -204,7 +204,7 @@ func (s *ImageDataTestSuite) TestDownloadStatusInternalServerError() {
 	imgdata, err := Download(context.Background(), s.server.URL, "Test image", DownloadOptions{}, security.DefaultOptions())
 
 	s.Require().Error(err)
-	s.Require().Equal(500, ierrors.Wrap(err, 0).StatusCode())
+	s.Require().Equal(502, ierrors.Wrap(err, 0).StatusCode())
 	s.Require().Nil(imgdata)
 }