aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2024-04-08 07:51:04 +0200
committerGitHub <noreply@github.com>2024-04-08 07:51:04 +0200
commit8aa088f7130d571ee6021d8547092162b3895b71 (patch)
tree66dfe5a98d18f7eba63b38c27683abce319fd39b
parentb732eede2738dcf88727b403fa1e9494466bf7a8 (diff)
downloaddendrite-8aa088f7130d571ee6021d8547092162b3895b71.tar.xz
Return correct Content-Type for unrecognized requests (#3355)
Fixes #3354
-rw-r--r--internal/httputil/routing.go4
-rw-r--r--internal/httputil/routing_test.go4
2 files changed, 4 insertions, 4 deletions
diff --git a/internal/httputil/routing.go b/internal/httputil/routing.go
index 2052c798..f5f1c652 100644
--- a/internal/httputil/routing.go
+++ b/internal/httputil/routing.go
@@ -66,15 +66,15 @@ func NewRouters() Routers {
}
var NotAllowedHandler = WrapHandlerInCORS(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(http.StatusMethodNotAllowed)
w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusMethodNotAllowed)
unrecognizedErr, _ := json.Marshal(spec.Unrecognized("Unrecognized request")) // nolint:misspell
_, _ = w.Write(unrecognizedErr) // nolint:misspell
}))
var NotFoundCORSHandler = WrapHandlerInCORS(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.WriteHeader(http.StatusNotFound)
w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusNotFound)
unrecognizedErr, _ := json.Marshal(spec.Unrecognized("Unrecognized request")) // nolint:misspell
_, _ = w.Write(unrecognizedErr) // nolint:misspell
}))
diff --git a/internal/httputil/routing_test.go b/internal/httputil/routing_test.go
index 21e2bf48..39ccd621 100644
--- a/internal/httputil/routing_test.go
+++ b/internal/httputil/routing_test.go
@@ -17,7 +17,7 @@ func TestRoutersError(t *testing.T) {
if rec.Code != http.StatusNotFound {
t.Fatalf("unexpected status code: %d - %s", rec.Code, rec.Body.String())
}
- if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
+ if ct := rec.Result().Header.Get("Content-Type"); ct != "application/json" {
t.Fatalf("unexpected content-type: %s", ct)
}
@@ -32,7 +32,7 @@ func TestRoutersError(t *testing.T) {
if rec.Code != http.StatusMethodNotAllowed {
t.Fatalf("unexpected status code: %d - %s", rec.Code, rec.Body.String())
}
- if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
+ if ct := rec.Result().Header.Get("Content-Type"); ct != "application/json" {
t.Fatalf("unexpected content-type: %s", ct)
}
}