Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
net/http: No easy way to get a server-side Request for testing. #9276
(net/http).Request is populated vastly differently on the client and server sides.
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.
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.