mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-02-02 11:34:20 +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
|
||||||
- Fix trimming of CMYK images.
|
- 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
|
## [3.6.0] - 2022-06-13
|
||||||
### Add
|
### Add
|
||||||
|
@ -2,7 +2,9 @@ package swift
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -46,12 +48,25 @@ 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))
|
object, objectHeaders, err := t.con.ObjectOpen(req.Context(), container, objectName, false, make(swift.Headers))
|
||||||
|
|
||||||
|
header := make(http.Header)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("error opening object: %v", err)
|
return nil, fmt.Errorf("error opening object: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
header := make(http.Header)
|
|
||||||
|
|
||||||
if config.ETagEnabled {
|
if config.ETagEnabled {
|
||||||
if etag, ok := objectHeaders["Etag"]; ok {
|
if etag, ok := objectHeaders["Etag"]; ok {
|
||||||
header.Set("ETag", etag)
|
header.Set("ETag", etag)
|
||||||
|
@ -90,6 +90,24 @@ func (s *SwiftTestSuite) TestRoundTripWithETagDisabledReturns200() {
|
|||||||
require.Equal(s.T(), 200, response.StatusCode)
|
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() {
|
func (s *SwiftTestSuite) TestRoundTripWithETagEnabled() {
|
||||||
config.ETagEnabled = true
|
config.ETagEnabled = true
|
||||||
request, _ := http.NewRequest("GET", "swift://test/foo/test.png", nil)
|
request, _ := http.NewRequest("GET", "swift://test/foo/test.png", nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user