Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 8aa088f

Browse files
authored
Return correct Content-Type for unrecognized requests (#3355)
Fixes #3354
1 parent b732eed commit 8aa088f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

internal/httputil/routing.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ func NewRouters() Routers {
6666
}
6767

6868
var NotAllowedHandler = WrapHandlerInCORS(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
69-
w.WriteHeader(http.StatusMethodNotAllowed)
7069
w.Header().Set("Content-Type", "application/json")
70+
w.WriteHeader(http.StatusMethodNotAllowed)
7171
unrecognizedErr, _ := json.Marshal(spec.Unrecognized("Unrecognized request")) // nolint:misspell
7272
_, _ = w.Write(unrecognizedErr) // nolint:misspell
7373
}))
7474

7575
var NotFoundCORSHandler = WrapHandlerInCORS(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
76-
w.WriteHeader(http.StatusNotFound)
7776
w.Header().Set("Content-Type", "application/json")
77+
w.WriteHeader(http.StatusNotFound)
7878
unrecognizedErr, _ := json.Marshal(spec.Unrecognized("Unrecognized request")) // nolint:misspell
7979
_, _ = w.Write(unrecognizedErr) // nolint:misspell
8080
}))

internal/httputil/routing_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestRoutersError(t *testing.T) {
1717
if rec.Code != http.StatusNotFound {
1818
t.Fatalf("unexpected status code: %d - %s", rec.Code, rec.Body.String())
1919
}
20-
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
20+
if ct := rec.Result().Header.Get("Content-Type"); ct != "application/json" {
2121
t.Fatalf("unexpected content-type: %s", ct)
2222
}
2323

@@ -32,7 +32,7 @@ func TestRoutersError(t *testing.T) {
3232
if rec.Code != http.StatusMethodNotAllowed {
3333
t.Fatalf("unexpected status code: %d - %s", rec.Code, rec.Body.String())
3434
}
35-
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
35+
if ct := rec.Result().Header.Get("Content-Type"); ct != "application/json" {
3636
t.Fatalf("unexpected content-type: %s", ct)
3737
}
3838
}

0 commit comments

Comments
 (0)