Adapted internal middleware

- redirect internally regardless of proxy status code
- support multiple internal redirects
This commit is contained in:
Michael Schoebel 2015-05-07 20:20:45 +02:00
parent 0650dd7171
commit a5b565e193

View File

@ -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)
}
}