Fixing deprecated: golang.org/x/oauth2: Transport.CancelRequest no longer does anything; use contexts

485 views
Skip to first unread message

cpu...@gmail.com

unread,
Mar 19, 2021, 12:44:21 PM3/19/21
to golang-nuts
Hi all,

I've recently learned about oauth2 and started to convert some of my "manual" code using net/http to use an  underlying oauth2.Transport for executing authenticated requests and token refresh.

As a result, my application now sometimes shows 

    deprecated: golang.org/x/oauth2: Transport.CancelRequest no longer does anything; use contexts

Of course, I'm nowhere calling that method. Digging into the default HTTP Client (https://github.com/golang/go/blob/a937729c2c2f6950a32bc5cd0f5b88700882f078/src/net/http/client.go) reads:

// For compatibility, the Client will also use the deprecated
// CancelRequest method on Transport if found. New
// RoundTripper implementations should use the Request's Context
// for cancellation instead of implementing CancelRequest.
Timeout time.Duration

I would read this as: if you have an http.Client with an underlying oauth2.Transport and the request times out, the oauth2.Transport's CancelRequest method will *always* be called and hence show the undesired warning.

Is that correct?

Thanks,
Andreas

cpu...@gmail.com

unread,
Mar 22, 2021, 5:26:03 AM3/22/21
to golang-nuts
Opened https://github.com/golang/oauth2/issues/487 to propose removing the `CancelRequest` method.

Cheers,
Andreas
Reply all
Reply to author
Forward
0 new messages