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(debug_mode): Fix FASTLY_DEBUG_MODE when used in combination with go-vcr. #561

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions fastly/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,22 @@ func (c *Client) Request(verb, p string, ro *RequestOptions) (*http.Response, er

if c.DebugMode {
r := req.Clone(context.Background())
// 'r' and 'req' both have a reference to a Body that
// is an io.Reader, but only one of them can read its
// contents since io.Reader is not seekable and cannot
// be rewound

r.Header.Del("Fastly-Key")
dump, _ := httputil.DumpRequest(r, true)

// httputil.DumpRequest has read the Body from 'r',
// and set r.Body to an io.ReadCloser that will return
// the same bytes as the original Body, so we can
// stuff that into 'req' for when the request is
// actually sent; it can't be read in 'r', but the
// lifetime of 'r' ends at the end of this block
req.Body = r.Body

fmt.Printf("http.Request (dump): %q\n", dump)
}

Expand Down
Loading