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/httptest: add NewRequestWithContext #59473

Closed
kevinburke opened this issue Apr 6, 2023 · 8 comments
Closed

net/http/httptest: add NewRequestWithContext #59473

kevinburke opened this issue Apr 6, 2023 · 8 comments

Comments

@kevinburke
Copy link
Contributor

Recently the net/http package added NewRequestWithContext, which allows callers to pass in a context.Context without a second method call and/or copying the http.Request.

The proposal is to add the same API to httptest, so users don't need to think about it or wonder why httptest does not expose the same API as net/http for creating requests.

Updates #23544.

@gopherbot gopherbot added this to the Proposal milestone Apr 6, 2023
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Apr 6, 2023
@ianlancetaylor
Copy link
Contributor

CC @neild @bradfitz

@neild
Copy link
Contributor

neild commented Apr 6, 2023

Seems reasonable to me.

@kevinburke
Copy link
Contributor Author

Does this need to go to the proposal committee or should I just submit a CL?

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/548355 mentions this issue: net/http/httptest: add NewRequestWithContext

@neild
Copy link
Contributor

neild commented Dec 14, 2023

This does need to be approved by the proposal committee, since it's adding a new exported function.

I think this change is reasonable, and support it.

@rsc
Copy link
Contributor

rsc commented Mar 1, 2024

Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group

The proposal is to add

func NewRequestWithContext(ctx context.Context, method, target string, body io.Reader) *http.Request

that behaves like httptest.NewRequest except it also adds a context.

@rsc rsc moved this from Incoming to Likely Accept in Proposals Mar 1, 2024
@rsc
Copy link
Contributor

rsc commented Mar 8, 2024

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group

The proposal is to add

func NewRequestWithContext(ctx context.Context, method, target string, body io.Reader) *http.Request

that behaves like httptest.NewRequest except it also adds a context.

@rsc rsc moved this from Likely Accept to Accepted in Proposals Mar 8, 2024
@rsc rsc changed the title proposal: net/http/httptest: add NewRequestWithContext net/http/httptest: add NewRequestWithContext Mar 8, 2024
@rsc rsc modified the milestones: Proposal, Backlog Mar 8, 2024
gopherbot pushed a commit that referenced this issue Mar 11, 2024
This matches the net/http API.

Updates #59473.

Change-Id: I99917cef3ed42a0b4a2b39230b492be00da8bbfd
Reviewed-on: https://go-review.googlesource.com/c/go/+/548355
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
@odeke-em
Copy link
Member

This got implemented by @kevinburke in CL https://go-review.googlesource.com/c/go/+/548355 but it used "Updates #NNN" instead of "Fixes #NNN" so Github didn't auto-close the issue, hence I am closing it right now. Thank you Kevin!

@dmitshur dmitshur modified the milestones: Backlog, Go1.23 Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Accepted
Development

No branches or pull requests

7 participants