fix: only redirect for GET/HEAD requests (#12702)

fixes #12701
This commit is contained in:
Harshavardhana 2021-07-13 11:25:08 -07:00 committed by GitHub
parent aa78505181
commit 9dae5a7c85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -154,15 +154,15 @@ func setRedirectHandler(h http.Handler) http.Handler {
func guessIsBrowserReq(r *http.Request) bool { func guessIsBrowserReq(r *http.Request) bool {
aType := getRequestAuthType(r) aType := getRequestAuthType(r)
ok := strings.Contains(r.Header.Get("User-Agent"), "Mozilla") && globalBrowserEnabled && return strings.Contains(r.Header.Get("User-Agent"), "Mozilla") &&
(aType == authTypeJWT || aType == authTypeAnonymous) globalBrowserEnabled && aType == authTypeAnonymous
return ok
} }
func setBrowserRedirectHandler(h http.Handler) http.Handler { func setBrowserRedirectHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
read := r.Method == http.MethodGet || r.Method == http.MethodHead
// Re-direction is handled specifically for browser requests. // Re-direction is handled specifically for browser requests.
if guessIsBrowserReq(r) { if guessIsBrowserReq(r) && read {
// Fetch the redirect location if any. // Fetch the redirect location if any.
if u := getRedirectLocation(r); u != nil { if u := getRedirectLocation(r); u != nil {
// Employ a temporary re-direct. // Employ a temporary re-direct.