From 201a20ac020c6d67c6ca920199555798fd4815ee Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 27 Nov 2016 16:30:46 -0800 Subject: [PATCH] handlers: Handle re-direction properly for S3 requests. (#3355) Make sure all S3 signature requests are not re-directed to `/minio`. This should be only done for JWT and some Anonymous requests. This also fixes a bug found from https://github.com/bji/libs3 ``` $ s3 -u list ERROR: XmlParseFailure ``` Now after this fix shows proper output ``` $ s3 -u list Bucket Created -------------------------------------------------------- -------------------- andoria 2016-11-27T08:19:06Z ``` --- cmd/generic-handlers.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/cmd/generic-handlers.go b/cmd/generic-handlers.go index b657edeca..d5e905136 100644 --- a/cmd/generic-handlers.go +++ b/cmd/generic-handlers.go @@ -81,22 +81,26 @@ func setBrowserRedirectHandler(h http.Handler) http.Handler { } func (h redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - // Re-direction handled specifically for browsers. - if strings.Contains(r.Header.Get("User-Agent"), "Mozilla") && !isRequestSignatureV4(r) { - switch r.URL.Path { - case "/", "/webrpc", "/login", "/favicon.ico": - // '/' is redirected to 'locationPrefix/' - // '/webrpc' is redirected to 'locationPrefix/webrpc' - // '/login' is redirected to 'locationPrefix/login' - location := h.locationPrefix + r.URL.Path - // Redirect to new location. - http.Redirect(w, r, location, http.StatusTemporaryRedirect) - return - case h.locationPrefix: - // locationPrefix is redirected to 'locationPrefix/' - location := h.locationPrefix + "/" - http.Redirect(w, r, location, http.StatusTemporaryRedirect) - return + aType := getRequestAuthType(r) + // Re-direct only for JWT and anonymous requests coming from web-browser. + if aType == authTypeJWT || aType == authTypeAnonymous { + // Re-direction handled specifically for browsers. + if strings.Contains(r.Header.Get("User-Agent"), "Mozilla") { + switch r.URL.Path { + case "/", "/webrpc", "/login", "/favicon.ico": + // '/' is redirected to 'locationPrefix/' + // '/webrpc' is redirected to 'locationPrefix/webrpc' + // '/login' is redirected to 'locationPrefix/login' + location := h.locationPrefix + r.URL.Path + // Redirect to new location. + http.Redirect(w, r, location, http.StatusTemporaryRedirect) + return + case h.locationPrefix: + // locationPrefix is redirected to 'locationPrefix/' + location := h.locationPrefix + "/" + http.Redirect(w, r, location, http.StatusTemporaryRedirect) + return + } } } h.handler.ServeHTTP(w, r)