mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-01-23 11:14:48 +02:00
Respond with 404 when the source image can not be found in OpenStack Swift (#903)
This commit is contained in:
parent
7a5074187e
commit
6f292443ea
@ -6,6 +6,7 @@
|
||||
|
||||
### Fix
|
||||
- Fix trimming of CMYK images.
|
||||
- Respond with 404 when the source image can not be found in OpenStack Object Storage.
|
||||
|
||||
## [3.6.0] - 2022-06-13
|
||||
### Add
|
||||
|
@ -2,7 +2,9 @@ package swift
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@ -46,11 +48,24 @@ func (t transport) RoundTrip(req *http.Request) (resp *http.Response, err error)
|
||||
|
||||
object, objectHeaders, err := t.con.ObjectOpen(req.Context(), container, objectName, false, make(swift.Headers))
|
||||
|
||||
header := make(http.Header)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error opening object: %v", err)
|
||||
if errors.Is(err, swift.ObjectNotFound) || errors.Is(err, swift.ContainerNotFound) {
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusNotFound,
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: header,
|
||||
Body: io.NopCloser(strings.NewReader(err.Error())),
|
||||
Close: false,
|
||||
Request: req,
|
||||
}, nil
|
||||
}
|
||||
|
||||
header := make(http.Header)
|
||||
return nil, fmt.Errorf("error opening object: %v", err)
|
||||
}
|
||||
|
||||
if config.ETagEnabled {
|
||||
if etag, ok := objectHeaders["Etag"]; ok {
|
||||
|
@ -90,6 +90,24 @@ func (s *SwiftTestSuite) TestRoundTripWithETagDisabledReturns200() {
|
||||
require.Equal(s.T(), 200, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripReturns404WhenObjectNotFound() {
|
||||
config.ETagEnabled = true
|
||||
request, _ := http.NewRequest("GET", "swift://test/foo/not-here.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 404, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripReturns404WhenContainerNotFound() {
|
||||
config.ETagEnabled = true
|
||||
request, _ := http.NewRequest("GET", "swift://invalid/foo/test.png", nil)
|
||||
|
||||
response, err := s.transport.RoundTrip(request)
|
||||
require.Nil(s.T(), err)
|
||||
require.Equal(s.T(), 404, response.StatusCode)
|
||||
}
|
||||
|
||||
func (s *SwiftTestSuite) TestRoundTripWithETagEnabled() {
|
||||
config.ETagEnabled = true
|
||||
request, _ := http.NewRequest("GET", "swift://test/foo/test.png", nil)
|
||||
|
Loading…
x
Reference in New Issue
Block a user