mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-06 00:17:27 +00:00
fix: set content-type header before status
This commit is contained in:
@@ -19,8 +19,8 @@ func DisallowNonNavigationalRequests(next http.Handler) http.Handler {
|
||||
span := trace.SpanFromContext(r.Context())
|
||||
span.SetAttributes(attribute.Bool("request.disallowed", true))
|
||||
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write([]byte(`{"error": "unauthenticated", "error_description": "this is an interactive endpoint; user-agents must be navigated to this endpoint", "error_path": "` + r.URL.Path + `"}`))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -203,12 +203,13 @@ func handleAutologin(src ReverseProxySource, w http.ResponseWriter, r *http.Requ
|
||||
|
||||
location := loginURL(target, "non-navigation request detected; responding with 401 and Location header")
|
||||
w.Header().Set("Location", location)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
|
||||
if httpinternal.Accepts(r, "*/*", "application/json") {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write([]byte(`{"error": "unauthenticated, please log in"}`))
|
||||
} else {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Write([]byte("unauthenticated, please log in"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user