Skip to content

Commit

Permalink
Detect loop and return 404
Browse files Browse the repository at this point in the history
  • Loading branch information
imranismail committed Nov 25, 2020
1 parent 979a9c1 commit e9aa6c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions proxy/error_boundary.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ func (eb *ErrorBoundary) ModifyRequest(req *http.Request) error {
func (eb *ErrorBoundary) ModifyResponse(res *http.Response) error {
defer eb.resv.ResetResponseVerifications()

ctx := martian.NewContext(res.Request)

if err, ok := ctx.Get("via.LoopDetection"); err != nil && ok {
res.Body.Close()
res.ContentLength = 0
res.Body = ioutil.NopCloser(bytes.NewReader([]byte{}))
res.StatusCode = http.StatusNotFound
res.Status = http.StatusText(res.StatusCode)

return nil
}

merr := martian.NewMultiError()

if eb.resmod != nil {
Expand Down
1 change: 1 addition & 0 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
_ "github.com/google/martian/v3/body"
_ "github.com/google/martian/v3/cookie"
_ "github.com/google/martian/v3/failure"
_ "github.com/google/martian/v3/fifo"
_ "github.com/google/martian/v3/header"
_ "github.com/google/martian/v3/martianurl"
_ "github.com/google/martian/v3/method"
Expand Down

0 comments on commit e9aa6c9

Please sign in to comment.