Make Transport.CancelRequest a no-op
Transport.CancelRequest has been deprecated since Go 1.6. It never worked for HTTP/2 requests. Supporting it for HTTP/1 is expensive: the transport must track every in-flight request in a map, just in case a caller wants to cancel one. Code that never calls CancelRequest pays this cost too.
Transport.CancelRequest will become a no-op. On its first call, it logs a one-time warning. To cancel requests, use a context instead:
ctx, cancel := context.WithCancel(context.Background())
req, _ := http.NewRequestWithContext(ctx, "GET", url, nil)
go func() { /* ... */ cancel() }()
resp, err := client.Do(req)
Setting GODEBUG=httptransportcancelrequest=1 restores the old behavior for four release cycles. After that, support is removed entirely.
- Proposal
- #79040 by neild
- Status
- Accepted on Jul 15, 2026
- Impact
- low
- Area
- net/http