From a5b565e1938652fcb38ce115f1ac0b90fb046e68 Mon Sep 17 00:00:00 2001 From: Michael Schoebel Date: Thu, 7 May 2015 20:20:45 +0200 Subject: [PATCH] Adapted internal middleware - redirect internally regardless of proxy status code - support multiple internal redirects --- middleware/internal/internal.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/middleware/internal/internal.go b/middleware/internal/internal.go index 67af49412..7678ee0a3 100644 --- a/middleware/internal/internal.go +++ b/middleware/internal/internal.go @@ -37,19 +37,13 @@ func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) iw := internalResponseWriter{ResponseWriter: w} status, err := i.Next.ServeHTTP(iw, r) - if isInternalRedirect(iw) && status < 400 { + for isInternalRedirect(iw) { // Redirect - adapt request URL path and send it again // "down the chain" r.URL.Path = iw.Header().Get(redirectHeader) iw.ClearHeader() status, err = i.Next.ServeHTTP(iw, r) - - if isInternalRedirect(iw) { - // multiple redirects not supported - iw.ClearHeader() - return http.StatusInternalServerError, nil - } } return status, err @@ -72,7 +66,7 @@ func (w internalResponseWriter) ClearHeader() { // WriteHeader ignores the call if the response should be redirected to an // internal location. func (w internalResponseWriter) WriteHeader(code int) { - if !isInternalRedirect(w) && code < 400 { + if !isInternalRedirect(w) { w.ResponseWriter.WriteHeader(code) } }