Fix Content-Type not being set on invalidAuthResponse

When `w.WriteHeader(...)` is called, the HTTP headers are written in
the HTTP response.

Therefore, calling `w.Header().Add(...)` after `w.WriteHeader(...)`
will not have any effect.

Signed-off-by: Ionut Balutoiu <ibalutoiu@cloudbasesolutions.com>
This commit is contained in:
Ionut Balutoiu 2023-07-18 16:42:32 +03:00
parent 8089244c9c
commit 4787622450

View file

@ -74,8 +74,8 @@ func (amw *jwtMiddleware) claimsToContext(ctx context.Context, claims *JWTClaims
}
func invalidAuthResponse(w http.ResponseWriter) {
w.WriteHeader(http.StatusUnauthorized)
w.Header().Add("Content-Type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
if err := json.NewEncoder(w).Encode(
apiParams.APIErrorResponse{
Error: "Authentication failed",