mirror of https://github.com/minio/minio.git
fix: handle redirects for specific resources (#12629)
This commit is contained in:
parent
25f55d6051
commit
c99d399d09
|
@ -114,13 +114,16 @@ func minioConfigToConsoleFeatures() {
|
|||
os.Setenv("CONSOLE_MINIO_SERVER", getAPIEndpoints()[0])
|
||||
if value := env.Get("MINIO_LOG_QUERY_URL", ""); value != "" {
|
||||
os.Setenv("CONSOLE_LOG_QUERY_URL", value)
|
||||
}
|
||||
if value := env.Get("MINIO_LOG_QUERY_AUTH_TOKEN", ""); value != "" {
|
||||
os.Setenv("CONSOLE_LOG_QUERY_AUTH_TOKEN", value)
|
||||
}
|
||||
}
|
||||
// Enable if prometheus URL is set.
|
||||
if value := env.Get("MINIO_PROMETHEUS_URL", ""); value != "" {
|
||||
os.Setenv("CONSOLE_PROMETHEUS_URL", value)
|
||||
if value := env.Get("MINIO_PROMETHEUS_JOB_ID", "minio-job"); value != "" {
|
||||
os.Setenv("CONSOLE_PROMETHEUS_JOB_ID", value)
|
||||
}
|
||||
}
|
||||
// Enable if LDAP is enabled.
|
||||
if globalLDAPConfig.Enabled {
|
||||
|
@ -413,11 +416,6 @@ func handleCommonEnvVars() {
|
|||
logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER value in environment variable")
|
||||
}
|
||||
|
||||
globalBrowserRedirect, err = config.ParseBool(env.Get(config.EnvBrowserRedirect, config.EnableOn))
|
||||
if err != nil {
|
||||
logger.Fatal(config.ErrInvalidBrowserValue(err), "Invalid MINIO_BROWSER_REDIRECT value in environment variable")
|
||||
}
|
||||
|
||||
globalFSOSync, err = config.ParseBool(env.Get(config.EnvFSOSync, config.EnableOff))
|
||||
if err != nil {
|
||||
logger.Fatal(config.ErrInvalidFSOSyncValue(err), "Invalid MINIO_FS_OSYNC value in environment variable")
|
||||
|
|
|
@ -22,6 +22,7 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
@ -161,10 +162,9 @@ func guessIsBrowserReq(r *http.Request) bool {
|
|||
func setBrowserRedirectHandler(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
// Re-direction is handled specifically for browser requests.
|
||||
if guessIsBrowserReq(r) && globalBrowserRedirect {
|
||||
if guessIsBrowserReq(r) {
|
||||
// Fetch the redirect location if any.
|
||||
u := getRedirectLocation(r)
|
||||
if u != nil {
|
||||
if u := getRedirectLocation(r); u != nil {
|
||||
// Employ a temporary re-direct.
|
||||
http.Redirect(w, r, u.String(), http.StatusTemporaryRedirect)
|
||||
return
|
||||
|
@ -184,33 +184,36 @@ func shouldProxy() bool {
|
|||
// serves only limited purpose on redirect-handler for
|
||||
// browser requests.
|
||||
func getRedirectLocation(r *http.Request) *url.URL {
|
||||
resource, err := getResource(r.URL.Path, r.Host, globalDomainNames)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, prefix := range []string{
|
||||
"favicon-16x16.png",
|
||||
"favicon-32x32.png",
|
||||
"favicon-96x96.png",
|
||||
"index.html",
|
||||
minioReservedBucket,
|
||||
} {
|
||||
bucket, _ := path2BucketObject(resource)
|
||||
if path.Clean(bucket) == prefix || resource == slashSeparator {
|
||||
hostname, _, _ := net.SplitHostPort(r.Host)
|
||||
if hostname == "" {
|
||||
hostname = r.Host
|
||||
}
|
||||
var rurl = &url.URL{
|
||||
return &url.URL{
|
||||
Host: net.JoinHostPort(hostname, globalMinioConsolePort),
|
||||
}
|
||||
urlPath := r.URL.Path
|
||||
Scheme: func() string {
|
||||
scheme := "http"
|
||||
if r.TLS != nil {
|
||||
scheme = "https"
|
||||
}
|
||||
rurl.Scheme = scheme
|
||||
if urlPath == minioReservedBucketPath {
|
||||
rurl.Path = minioReservedBucketPath + SlashSeparator
|
||||
return scheme
|
||||
}(),
|
||||
}
|
||||
if contains([]string{
|
||||
SlashSeparator,
|
||||
"/webrpc",
|
||||
"/login",
|
||||
"/favicon-16x16.png",
|
||||
"/favicon-32x32.png",
|
||||
"/favicon-96x96.png",
|
||||
}, urlPath) {
|
||||
rurl.Path = minioReservedBucketPath + urlPath
|
||||
}
|
||||
return rurl
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// guessIsHealthCheckReq - returns true if incoming request looks
|
||||
|
|
|
@ -137,9 +137,6 @@ var (
|
|||
// This flag is set to 'true' by default
|
||||
globalBrowserEnabled = true
|
||||
|
||||
// This flag is set to 'true' by default.
|
||||
globalBrowserRedirect = true
|
||||
|
||||
// This flag is set to 'true' when MINIO_UPDATE env is set to 'off'. Default is false.
|
||||
globalInplaceUpdateDisabled = false
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ const (
|
|||
EnvRootPassword = "MINIO_ROOT_PASSWORD"
|
||||
|
||||
EnvBrowser = "MINIO_BROWSER"
|
||||
EnvBrowserRedirect = "MINIO_BROWSER_REDIRECT"
|
||||
EnvDomain = "MINIO_DOMAIN"
|
||||
EnvRegionName = "MINIO_REGION_NAME"
|
||||
EnvPublicIPs = "MINIO_PUBLIC_IPS"
|
||||
|
|
Loading…
Reference in New Issue