You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposal: add a context-aware client that is similar to/mirrors http.Client.
req, _ := http.NewRequest(...)
ctx := context.Background()
c := ctxhttp.NewClient(http.DefaultClient)
// Add the ctx parameter to Do()
resp, err := c.Do(ctx, req)
Should this type go into x/net/context/ctxhttp? The package shouldn't be called http, since something like this would need to be used in conjunction with net/http.
Is Get(), Post(), etc needed, or do we only need Do(ctx, req)?
I'd rather not see two types of *http.Client splitting the API ecosystem. In Go 1.5, *http.Request has a Cancel field that's the same as the Done channel's return type. I'd rather just see a helper package if anything that doesn't introduce new types. If it really has to, maybe it could introduce a new RoundTripper (but returning a RoundTripper and not its own *Transport type), but I'd rather see no new types.
Activity
ianlancetaylor commentedon Jul 28, 2015
CC @Sajmani
bradfitz commentedon Jul 28, 2015
I'd rather not see two types of *http.Client splitting the API ecosystem. In Go 1.5, *http.Request has a Cancel field that's the same as the Done channel's return type. I'd rather just see a helper package if anything that doesn't introduce new types. If it really has to, maybe it could introduce a new RoundTripper (but returning a RoundTripper and not its own *Transport type), but I'd rather see no new types.
broady commentedon Jul 28, 2015
@bradfitz So, I guess just a function like
Do(httpClient, ctx, req)then?I don't think a RoundTripper works, it goes against the intent of the context package by putting a
Contextinto a struct.bradfitz commentedon Jul 28, 2015
Making a request just for GET is annoying, so probably also
GET.Be sure to also file a bug against Google's internal codebase to make sure all our various
RoundTrippers support the new Cancel field.adg commentedon Jul 28, 2015
If you're making a package for helpers, might as well do the full set of
helpers we have in the standard library:
func Get(url string) (resp *Response, err error)
func Head(url string) (resp *Response, err error)
func Post(url string, bodyType string, body io.Reader) (resp *Response, err
error)
func PostForm(url string, data url.Values) (resp *Response, err error)
On 28 July 2015 at 15:56, Brad Fitzpatrick [email protected] wrote:
[-]proposal: x/net/context: Context-aware HTTP client.[/-][+]proposal: x/net/context: Context-aware HTTP helper functions.[/+]broady commentedon Jul 28, 2015
Not sure why Gerrit didn't link this issue, but the change that implements this is at http://golang.org/cl/12755.
I added helpers for Do/Get/Head/Post/PostForm.
The function signatures are
X(http.Client, context.Context, ...)whereXis Do/Get/...gopherbot commentedon Jul 28, 2015
CL https://golang.org/cl/12755 mentions this issue.
adg commentedon Jul 28, 2015
Sometimes the notifications take a little while to come through.
On 28 July 2015 at 18:01, GopherBot [email protected] wrote: