mirror of
https://github.com/caddyserver/caddy.git
synced 2025-03-07 12:33:56 +03:00
Adapted internal middleware
- Detect too many internal redirects - return 500 in this case
This commit is contained in:
parent
a5b565e193
commit
e3d64169ed
1 changed files with 11 additions and 2 deletions
|
@ -16,7 +16,10 @@ type Internal struct {
|
|||
Paths []string
|
||||
}
|
||||
|
||||
const redirectHeader string = "X-Accel-Redirect"
|
||||
const (
|
||||
redirectHeader string = "X-Accel-Redirect"
|
||||
maxRedirectCount int = 10
|
||||
)
|
||||
|
||||
func isInternalRedirect(w http.ResponseWriter) bool {
|
||||
return w.Header().Get(redirectHeader) != ""
|
||||
|
@ -37,7 +40,7 @@ func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
|||
iw := internalResponseWriter{ResponseWriter: w}
|
||||
status, err := i.Next.ServeHTTP(iw, r)
|
||||
|
||||
for isInternalRedirect(iw) {
|
||||
for c := 0; c < maxRedirectCount && isInternalRedirect(iw); c++ {
|
||||
// Redirect - adapt request URL path and send it again
|
||||
// "down the chain"
|
||||
r.URL.Path = iw.Header().Get(redirectHeader)
|
||||
|
@ -46,6 +49,12 @@ func (i Internal) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
|
|||
status, err = i.Next.ServeHTTP(iw, r)
|
||||
}
|
||||
|
||||
if isInternalRedirect(iw) {
|
||||
// Too many redirect cycles
|
||||
iw.ClearHeader()
|
||||
return http.StatusInternalServerError, nil
|
||||
}
|
||||
|
||||
return status, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue