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: clarify docs on ResponseWriter.Write and Response.Write #8991

Closed
gopherbot opened this issue Oct 24, 2014 · 3 comments
Closed

net/http: clarify docs on ResponseWriter.Write and Response.Write #8991

gopherbot opened this issue Oct 24, 2014 · 3 comments

Comments

@gopherbot
Copy link

by opennota:

When writing to the http.ResponseWriter, the http.Response's method Write doesn't do
what is expected.

    func handler(w http.ResponseWriter, r *http.Request) {
        resp, _ := client.Get("http://google.com/";)
        resp.Write(w)
    }

This will write resp's headers to the *body* of the handler's response, with the
text/plain content type.

A method that *copies* a Response would be helpful.
@bradfitz
Copy link
Contributor

Comment 1:

We can't change the behavior here even if we wanted to, but we can clarify things in the
documentation.

Labels changed: added documentation, release-go1.5.

Status changed to Accepted.

@gopherbot
Copy link
Author

CL https://golang.org/cl/9410 mentions this issue.

mk0x9 pushed a commit to mk0x9/go that referenced this issue Apr 28, 2015
Fixes golang#10366 (how to set custom headers)
Fixes golang#9836 (PATCH in PostForm)
Fixes golang#9276 (generating a server-side Request for testing)
Update golang#8991 (clarify Response.Write for now; export ReverseProxy's copy later?)

Change-Id: I95a11bf3bb3eeeeb72775b6ebfbc761641addc35
Reviewed-on: https://go-review.googlesource.com/9410
Reviewed-by: David Crawshaw <crawshaw@golang.org>
@bradfitz
Copy link
Contributor

I don't think there's much more to do here. I looked at exporting the guts of net/http/httputil.ReverseProxy's copy function, but there's nothing to be extracted that can't be used via making a ReverseProxy and then calling its ServeHTTP.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
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

3 participants