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

do we need to close the resp? #1

Open
useryq8 opened this issue May 8, 2024 · 1 comment
Open

do we need to close the resp? #1

useryq8 opened this issue May 8, 2024 · 1 comment

Comments

@useryq8
Copy link

useryq8 commented May 8, 2024

it has the built-in close

@ahuigo
Copy link
Owner

ahuigo commented May 11, 2024

In general, users do not need to remember to close the body connection at all times.

If you don't wanna close resp, try the latest version example: https://github.com/ahuigo/requests/blob/master/examples/timeout_test.go

	// Do not close body
	session := requests.R().SetDoNotCloseBody(true)
	resp, err := session.Get(ts.URL + "/get")
	if err == nil {
		var json map[string]interface{}
		err = resp.Json(&json)
		t.Logf("response json:%#v\n", json)
	}
	if err != nil {
		t.Fatal(err)
	}
	resp.R.Body.Close() // close body manually

Does it satisfy your needs?

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