Skip to content

Commit

Permalink
Merge pull request #711 from stripe/brandur-set-getbody
Browse files Browse the repository at this point in the history
Set `Request.GetBody`
  • Loading branch information
brandur-stripe authored Oct 29, 2018
2 parents 08bc5b8 + ea896e7 commit ddcffea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ env:
- STRIPE_MOCK_VERSION=0.33.0

go:
- "1.7"
- "1.8"
- "1.9"
- "1.10"
- "1.11"
- tip

language: go
Expand Down
12 changes: 12 additions & 0 deletions stripe.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,18 @@ func (s *BackendImplementation) Do(req *http.Request, body *bytes.Buffer, v inte
reader := bytes.NewReader(body.Bytes())

req.Body = nopReadCloser{reader}

// And also add the same thing to `Request.GetBody`, which allows
// `net/http` to get a new body in cases like a redirect. This is
// usually not used, but it doesn't hurt to set it in case it's
// needed. See:
//
// https://github.com/stripe/stripe-go/issues/710
//
req.GetBody = func() (io.ReadCloser, error) {
reader := bytes.NewReader(body.Bytes())
return nopReadCloser{reader}, nil
}
}

res, err = s.HTTPClient.Do(req)
Expand Down

0 comments on commit ddcffea

Please sign in to comment.