From 9b6664399f804428829b2cd67e5c5dc7450a9ad9 Mon Sep 17 00:00:00 2001 From: mstar Date: Wed, 9 Apr 2025 13:11:12 +0200 Subject: [PATCH] Fix header write order Headers need to be written before status code --- http/httpErr.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http/httpErr.go b/http/httpErr.go index 6780419..61337a1 100644 --- a/http/httpErr.go +++ b/http/httpErr.go @@ -32,8 +32,8 @@ func ProblemDetails( details *string, extras map[string]any, ) { - w.WriteHeader(statusCode) w.Header().Add("Content-Type", "application/problem+json") + w.WriteHeader(statusCode) data := map[string]any{ "type": errorType, "status": statusCode, @@ -58,8 +58,8 @@ func ProblemDetails( // Write a simple problem details response. // It only provides the status code, as defined in RFC 9457, section 4.2.1 func ProblemDetailsStatusOnly(w http.ResponseWriter, statusCode int) { - w.WriteHeader(statusCode) w.Header().Add("Content-Type", "application/problem+json") + w.WriteHeader(statusCode) data := map[string]any{ "type": "about:blank", "title": http.StatusText(statusCode),