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

Wrong Response Request Body #100

Closed
systemstart opened this issue Aug 26, 2022 · 3 comments
Closed

Wrong Response Request Body #100

systemstart opened this issue Aug 26, 2022 · 3 comments

Comments

@systemstart
Copy link

Was reading the code.

The given line should use Request instead of Response, right?

bodyReadCloser := io.NopCloser(bytes.NewReader(trk.Response.Body))

The Content Length is correctly using the Request Body:

ContentLength: int64(len(trk.Request.Body)),

Didn't check for impact.

@seborama
Copy link
Owner

seborama commented Aug 26, 2022

Hey, that's a nifty find!

It's been on my radar that some of these helper methods aren't directly tested...

Impact is a little indirect i.e. when Response.Request.Body is referenced. I expect this to be uncommon but nonetheless that's wrong as it stands right now. It does not affect request matching (which obviously takes place before the response is provided).

The contents of the cassette on file is not affected because the whole Response.Request is constructed after the cassette is loaded and after the request has been matched. Note that in the HTTP transaction itself, Response.Request.Body is always nil as per https://pkg.go.dev/net/http#Response Request's Body is nil (having already been consumed) and govcr respects this.

The only time Response.Request.Body may be populated is transiently for the request mutators.
GoVCR ref:

The track replaying mutator additionally receives an informational copy of the current HTTP request in the track's Response under the Request field i.e. Track.Response.Request. This is useful for tailoring track replays with current request information. See TestExample3 for illustration.

This happens in pcb.replayTrack().

Again, real cool find. I'll patch this first and then beef up the tests for future-proofing 🤦

@seborama seborama changed the title Wrong Request Body Wrong Response Request Body Aug 26, 2022
@seborama
Copy link
Owner

v12.1.0 fixes the issue.
I'll keep this issue open until I've added the tests.

@seborama
Copy link
Owner

Tests added.

Thanks for raising this issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants