mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-01-08 10:45:04 +02:00
GCS transport should return 404 if bucket/object is not found
This commit is contained in:
parent
badf8303a2
commit
6cc887dfc4
@ -21,6 +21,7 @@
|
||||
### Fix
|
||||
- Fix trimming of CMYK images.
|
||||
- Respond with 404 when the source image can not be found in OpenStack Object Storage.
|
||||
- Respond with 404 when file wasn't found in the GCS storage.
|
||||
|
||||
## [3.6.0] - 2022-06-13
|
||||
### Add
|
||||
|
@ -3,6 +3,7 @@ package gcs
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -62,7 +63,7 @@ func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
if config.ETagEnabled {
|
||||
attrs, err := obj.Attrs(req.Context())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return handleError(req, err)
|
||||
}
|
||||
header.Set("ETag", attrs.Etag)
|
||||
|
||||
@ -83,7 +84,7 @@ func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
|
||||
reader, err := obj.NewReader(req.Context())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return handleError(req, err)
|
||||
}
|
||||
|
||||
header.Set("Cache-Control", reader.Attrs.CacheControl)
|
||||
@ -101,3 +102,21 @@ func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
Request: req,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func handleError(req *http.Request, err error) (*http.Response, error) {
|
||||
if err != storage.ErrBucketNotExist && err != storage.ErrObjectNotExist {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusNotFound,
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: make(http.Header),
|
||||
ContentLength: int64(len(err.Error())),
|
||||
Body: io.NopCloser(strings.NewReader(err.Error())),
|
||||
Close: false,
|
||||
Request: req,
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user