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

Comments

Projects
None yet
5 participants
@bcmills
Copy link
Member

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

This comment has been minimized.

Copy link
Member

commented Dec 13, 2014

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 bradfitz added release-go1.5 and removed release-none labels Dec 13, 2014

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014

@bradfitz bradfitz removed the release-go1.5 label Dec 16, 2014

@rsc rsc removed accepted labels Apr 14, 2015

@bradfitz

This comment has been minimized.

Copy link
Member

commented Apr 21, 2015

@bcmills

This comment has been minimized.

Copy link
Member Author

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

This comment has been minimized.

Copy link
Member

commented Apr 22, 2015

Yeah, I'll clarify the docs.

@gopherbot

This comment has been minimized.

Copy link

commented Apr 28, 2015

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

@bradfitz bradfitz closed this in 339cf98 Apr 28, 2015

@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.
You can’t perform that action at this time.