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: always providing a readable body #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fredmaggiowski
Copy link

No description provided.

@davidebianchi davidebianchi linked an issue Jun 21, 2020 that may be closed by this pull request
}

defer func() {
resp.Body.Close()
resp.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this way we copy 2 times the response body, but the common library use case is to access to the json response body and unmarshal it in a given structure. So this change is an unnecessary copy of a possibly large body.

What's your use case to reuse the response body?
What do you think about set this behaviour under an option flag in client creation?

main.go Outdated Show resolved Hide resolved
main_test.go Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

HTTP response body can't be read multiple times
2 participants