Standard library / net/http
http.Transport.CancelRequest()
Deprecated: cancels an in-flight request on the transport; use request contexts instead. This example calls it on an inactive request only. Expected stdout: 'inactive request\n'.
Formal Syntax & Structure
go syntaxgo
func (t *Transport) CancelRequest(req *Request)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| req | *Request | HTTP request associated with the operation. |
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http")
func main() { tr := &http.Transport{} r := must(http.NewRequest("GET", "http://example.invalid/", nil)) tr.CancelRequest(r) fmt.Println("inactive request")}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}