mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-21 14:11:22 +02:00
Add Content-Type: text/plain
header to custom transports' error responses
This commit is contained in:
@@ -93,7 +93,7 @@ func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: http.Header{},
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(body.Len()),
|
||||
Body: io.NopCloser(body),
|
||||
Close: false,
|
||||
@@ -138,7 +138,7 @@ func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: header,
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(body.Len()),
|
||||
Body: io.NopCloser(body),
|
||||
Close: false,
|
||||
|
@@ -122,7 +122,7 @@ func respNotFound(req *http.Request, msg string) *http.Response {
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: make(http.Header),
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(len(msg)),
|
||||
Body: io.NopCloser(strings.NewReader(msg)),
|
||||
Close: false,
|
||||
|
@@ -88,7 +88,7 @@ func (t transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: http.Header{},
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(body.Len()),
|
||||
Body: io.NopCloser(body),
|
||||
Close: false,
|
||||
@@ -196,7 +196,7 @@ func handleError(req *http.Request, err error) (*http.Response, error) {
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: make(http.Header),
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(len(err.Error())),
|
||||
Body: io.NopCloser(strings.NewReader(err.Error())),
|
||||
Close: false,
|
||||
|
@@ -111,7 +111,7 @@ func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: http.Header{},
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(body.Len()),
|
||||
Body: io.NopCloser(body),
|
||||
Close: false,
|
||||
@@ -318,16 +318,14 @@ func handleError(req *http.Request, err error) (*http.Response, error) {
|
||||
return nil, ierrors.Wrap(err, 0)
|
||||
}
|
||||
|
||||
body := strings.NewReader(err.Error())
|
||||
|
||||
return &http.Response{
|
||||
StatusCode: rerr.Response.StatusCode,
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: http.Header{},
|
||||
ContentLength: int64(body.Len()),
|
||||
Body: io.NopCloser(body),
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(len(err.Error())),
|
||||
Body: io.NopCloser(strings.NewReader(err.Error())),
|
||||
Close: false,
|
||||
Request: req,
|
||||
}, nil
|
||||
|
@@ -60,7 +60,7 @@ func (t transport) RoundTrip(req *http.Request) (resp *http.Response, err error)
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: http.Header{},
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(body.Len()),
|
||||
Body: io.NopCloser(body),
|
||||
Close: false,
|
||||
@@ -80,14 +80,15 @@ func (t transport) RoundTrip(req *http.Request) (resp *http.Response, err error)
|
||||
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,
|
||||
StatusCode: http.StatusNotFound,
|
||||
Proto: "HTTP/1.0",
|
||||
ProtoMajor: 1,
|
||||
ProtoMinor: 0,
|
||||
Header: http.Header{"Content-Type": {"text/plain"}},
|
||||
ContentLength: int64(len(err.Error())),
|
||||
Body: io.NopCloser(strings.NewReader(err.Error())),
|
||||
Close: false,
|
||||
Request: req,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user