Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ModifyResponse call to context.Get #299

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions header/via_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (m *ViaModifier) ModifyRequest(req *http.Request) error {

if v := req.Header.Get("Via"); v != "" {
if m.hasLoop(v) {
err := fmt.Errorf("via: detected request loop, header contains %s", via)
err := fmt.Errorf("via.ModifyRequest: detected request loop, header contains %s", via)

ctx := martian.NewContext(req)
ctx.Set(viaLoopKey, err)
Expand All @@ -76,11 +76,10 @@ func (m *ViaModifier) ModifyRequest(req *http.Request) error {
func (m *ViaModifier) ModifyResponse(res *http.Response) error {
ctx := martian.NewContext(res.Request)

if err, _ := ctx.Get(viaLoopKey); err != nil {
if _, ok := ctx.Get(viaLoopKey); ok {
res.StatusCode = 400
res.Status = http.StatusText(400)

return err.(error)
return fmt.Errorf("via.ModifyResponse: detected request loop")
}

return nil
Expand Down