Skip to content

Commit

Permalink
Merge pull request #508 from battlecode/jerrym-fix-redirect
Browse files Browse the repository at this point in the history
Follow redirects on POST requests
  • Loading branch information
j-mao authored Jan 9, 2023
2 parents 42f03c3 + c42a92e commit 5841f2b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions saturn/pkg/saturn/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ func NewGCPTokenedReporter(
if err != nil {
return nil, fmt.Errorf("idtoken.NewClient: %v", err)
}

// Allow following redirect for POST requests
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
if len(via) >= 10 {
return fmt.Errorf("stopped after 10 redirects")
}
if via[0].GetBody == nil {
return fmt.Errorf("could not get original body")
}

var err error
req.Method = http.MethodPost
req.Body, err = via[0].GetBody()
if err != nil {
return fmt.Errorf("GetBody: %v", err)
}
return nil
}
return &GCPTokenedReporter{client, userAgent}, nil
}

Expand Down

0 comments on commit 5841f2b

Please sign in to comment.