redirect to console project for browser (#12172)

This commit is contained in:
Harshavardhana 2021-04-27 16:39:41 -07:00 committed by GitHub
parent 9e797532dc
commit 301669cf7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -131,8 +131,26 @@ const (
loginPathPrefix = SlashSeparator + "login"
)
// guessIsBrowserReq - returns true if the request is browser.
// This implementation just validates user-agent and
// looks for "Mozilla" string. This is no way certifiable
// way to know if the request really came from a browser
// since User-Agent's can be arbitrary. But this is just
// a best effort function.
func guessIsBrowserReq(req *http.Request) bool {
if req == nil {
return false
}
aType := getRequestAuthType(req)
return strings.Contains(req.Header.Get("User-Agent"), "Mozilla") && (aType == authTypeJWT || aType == authTypeAnonymous)
}
func setRedirectHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if guessIsBrowserReq(r) {
http.Redirect(w, r, "https://github.com/minio/console", http.StatusMovedPermanently)
return
}
if !shouldProxy() || guessIsRPCReq(r) || guessIsHealthCheckReq(r) ||
guessIsMetricsReq(r) || isAdminReq(r) {
h.ServeHTTP(w, r)