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

net/http: Documentation of implementation details for clients #3359

Closed
gopherbot opened this issue Mar 20, 2012 · 10 comments
Closed

net/http: Documentation of implementation details for clients #3359

gopherbot opened this issue Mar 20, 2012 · 10 comments

Comments

@gopherbot
Copy link

by elazarl:

In the net/http package there are three ways to send a request and receive a response.

The first one is, writing and reading the request directly from socket

The second one, using Transport.RoundTrip,

And the third is using Client.Do

The documentation is lacking as to what each of these is doing in edge cases.

For example, all will handle chunked encoding for you. The response.Body will never
return a non-chunked encoding you have to parse.

If you did not add directly Accept-Encoding:gzip, Transport is going to add that for
you, and will wrap the repsonse.Body with gzip.NewReader (sort of, it will also close
the original stream when closed).

Finally, client.Do, will also follow redirect responses (301 moved response will trigger
another request).

There may be more differences I didn't notice.

This behavior, kind-of makes sense, but it must be documented in the appropriate
functions.

See attached file for a demonstration of the different behaviours (note: leaks tcp
connection if using it too much). Run it with `go run sendreq.go` and see the response.
Change the code to discover more cases of different behavior.

Attachments:

  1. sendreq.go (1503 bytes)
@gopherbot
Copy link
Author

Comment 1 by sdegutis@8thlight.com:

I second this. I've been very intimidated by the net/http package so far, even after
reading many of the functions'/types' documentation. A clearer description of how to
jump in at a high level would be useful.

@dsymonds
Copy link
Contributor

Comment 2:

Brad, should we try to document this better for Go 1?

Labels changed: added priority-go1, documentation, removed priority-triage.

Owner changed to @bradfitz.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Mar 26, 2012

Comment 3:

Too late; can be done after Go 1.

Labels changed: added priority-later, removed priority-go1.

@rsc
Copy link
Contributor

rsc commented Sep 12, 2012

Comment 4:

Labels changed: added go1.1.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 5:

Labels changed: added size-m.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 6:

Labels changed: added suggested.

@bradfitz
Copy link
Contributor

Comment 7:

Sent out https://golang.org/cl/7606044

Labels changed: removed suggested.

Status changed to Started.

@gopherbot
Copy link
Author

Comment 8 by elazarl:

Brad,
Thanks for handling this. I think you still need to note that RoundTrip will add
Accept-gzip header and would gunzip if it didn't exist.

@bradfitz
Copy link
Contributor

Comment 9:

Done. I've now also documented the two undocumented Disable* fields on Transport with
the details of how Accept-Encoding: gzip works.

@bradfitz
Copy link
Contributor

Comment 10:

This issue was closed by revision 864278a.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants