Skip to content

Commit

Permalink
api: Delegate OPTIONS requests to auth server (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges authored May 10, 2023
1 parent 90c45b1 commit 5b80ee2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,16 @@ func authorization(authUrl string) middleware {
respondError(rw, http.StatusInternalServerError, fmt.Errorf("error authorizing request: %w", err))
return
}
defer authRes.Body.Close()

copyHeaders(proxiedResponseHeaders, authRes.Header, rw.Header())

// if this is an OPTIONS request, we just proxy the CORS logic from the auth server
if r.Method == http.MethodOptions && authRes.StatusCode == http.StatusNoContent {
rw.WriteHeader(http.StatusNoContent)
return
}

if authRes.StatusCode != http.StatusOK && authRes.StatusCode != http.StatusNoContent {
if contentType := authRes.Header.Get("Content-Type"); contentType != "" {
rw.Header().Set("Content-Type", contentType)
Expand Down

0 comments on commit 5b80ee2

Please sign in to comment.