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
Comments
I'm fine with this in 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. |
Wait, isn't this just http://golang.org/pkg/net/http/#ReadRequest ? |
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. |
Yeah, I'll clarify the docs. |
CL https://golang.org/cl/9410 mentions this issue. |
(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.
The text was updated successfully, but these errors were encountered: