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: No easy way to get a server-side Request for testing. #9276

Closed
bcmills opened this issue Dec 12, 2014 · 5 comments
Closed

net/http: No easy way to get a server-side Request for testing. #9276

bcmills opened this issue Dec 12, 2014 · 5 comments

Comments

@bcmills
Copy link
Contributor

bcmills commented Dec 12, 2014

(net/http).Request is populated vastly differently on the client and server sides.
That's probably not fixable, given Go1 compatibility.

But it causes problems when testing http handlers - httptest.ResponseRecorder needs a Request to go with it, and the obvious candidate (http.NewRequest) generates the client-side version, not the server-side version.

You can get the server-side version by setting up an httptest.Server and making a request to it, but that involves a lot of boilerplate and some syscalls.

It would be nice if there were a way (in the http or httptest package) to get a Request in the server-side format without having to go through the whole HTTP stack with a real server.

@bradfitz
Copy link
Contributor

I'm fine with this in net/http/httputil or net/http/httptest but not net/http, as we're trying to stop growing that.

API proposal? For simplicity of callers you might want this to return a single value instead of (*Request, error) but depending on what input you're imagining, returning an error might be inevitable.

@bradfitz
Copy link
Contributor

Wait, isn't this just http://golang.org/pkg/net/http/#ReadRequest ?

@bcmills
Copy link
Contributor Author

bcmills commented Apr 22, 2015

Maybe? For some reason I thought that ReadRequest generated a client-side request rather than a server-side one. Perhaps this is just a documentation issue.

@bradfitz
Copy link
Contributor

Yeah, I'll clarify the docs.

@gopherbot
Copy link

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

@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

5 participants