Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
set cors headers independently to the response status code (#72)
Browse files Browse the repository at this point in the history
Co-authored-by: Frederic Reisenhauer <f.reisenhauer@mittwald.de>
  • Loading branch information
freisenhauer and freisenhauer-mittwald authored Aug 10, 2023
1 parent 16cd11a commit 04d9787
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions auth/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ func (a *RestAuthDecorator) RegisterRoutes(mux *httprouter.Router) error {
uri, func(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
var authRequest ExternalAuthenticationRequest
var genericBody map[string]interface{}

h := rw.Header()
if a.authHandler.config.EnableCORS {
setCORSHeaders(h)
}

requestBody, err := io.ReadAll(req.Body)
if err != nil {
handleError(err, rw)
Expand Down Expand Up @@ -252,12 +258,6 @@ func (a *RestAuthDecorator) RegisterRoutes(mux *httprouter.Router) error {
return
}

h := rw.Header()

if a.authHandler.config.EnableCORS {
setCORSHeaders(h)
}

h.Set("Content-Type", "application/json;charset=utf8")
_, _ = rw.Write(jsonResponse)
},
Expand Down

0 comments on commit 04d9787

Please sign in to comment.