Add Content-Type: text/plain header to custom transports' error responses

This commit is contained in:
DarthSim
2025-03-23 18:41:41 +03:00
parent 10285240a9
commit ca18921c13
5 changed files with 19 additions and 20 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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

View File

@@ -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
}