mirror of
https://github.com/caddyserver/caddy.git
synced 2025-07-09 03:04:57 -04:00
Adapted internal middleware
- redirect internally regardless of proxy status code - support multiple internal redirects
This commit is contained in:
parent
0650dd7171
commit
a5b565e193
@ -37,19 +37,13 @@ func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
|||||||
iw := internalResponseWriter{ResponseWriter: w}
|
iw := internalResponseWriter{ResponseWriter: w}
|
||||||
status, err := i.Next.ServeHTTP(iw, r)
|
status, err := i.Next.ServeHTTP(iw, r)
|
||||||
|
|
||||||
if isInternalRedirect(iw) && status < 400 {
|
for isInternalRedirect(iw) {
|
||||||
// Redirect - adapt request URL path and send it again
|
// Redirect - adapt request URL path and send it again
|
||||||
// "down the chain"
|
// "down the chain"
|
||||||
r.URL.Path = iw.Header().Get(redirectHeader)
|
r.URL.Path = iw.Header().Get(redirectHeader)
|
||||||
iw.ClearHeader()
|
iw.ClearHeader()
|
||||||
|
|
||||||
status, err = i.Next.ServeHTTP(iw, r)
|
status, err = i.Next.ServeHTTP(iw, r)
|
||||||
|
|
||||||
if isInternalRedirect(iw) {
|
|
||||||
// multiple redirects not supported
|
|
||||||
iw.ClearHeader()
|
|
||||||
return http.StatusInternalServerError, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return status, err
|
return status, err
|
||||||
@ -72,7 +66,7 @@ func (w internalResponseWriter) ClearHeader() {
|
|||||||
// WriteHeader ignores the call if the response should be redirected to an
|
// WriteHeader ignores the call if the response should be redirected to an
|
||||||
// internal location.
|
// internal location.
|
||||||
func (w internalResponseWriter) WriteHeader(code int) {
|
func (w internalResponseWriter) WriteHeader(code int) {
|
||||||
if !isInternalRedirect(w) && code < 400 {
|
if !isInternalRedirect(w) {
|
||||||
w.ResponseWriter.WriteHeader(code)
|
w.ResponseWriter.WriteHeader(code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user