Skip to content

net/http: Client panics if RoundTripper returns neither response nor error #33563

@Teelevision

Description

@Teelevision

What did you do?

Use a http.RoundTripper that returns neither response nor error.

https://play.golang.org/p/EGEjS2P2xQI

What did you expect to see?

Documentation that the RoundTripper MUST return either response or error.

What did you see instead?

go/src/net/http/client.go

Lines 119 to 125 in 1dc0110

// RoundTrip should not attempt to interpret the response. In
// particular, RoundTrip must return err == nil if it obtained
// a response, regardless of the response's HTTP status code.
// A non-nil err should be reserved for failure to obtain a
// response. Similarly, RoundTrip should not attempt to
// handle higher-level protocol details such as redirects,
// authentication, or cookies.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0xffffffff addr=0x0 pc=0x24bc42]

goroutine 1 [running]:
net/http.redirectBehavior(0x311a6b, 0x3, 0x0, 0x84c510, 0x0, 0x0, 0x0, 0x0)
	/usr/local/go/src/net/http/client.go:422 +0x22
net/http.(*Client).do(0x840940, 0x84c510, 0x0, 0x0, 0x0, 0x0)
	/usr/local/go/src/net/http/client.go:655 +0x3a0
net/http.(*Client).Do(...)
	/usr/local/go/src/net/http/client.go:509
net/http.(*Client).Get(0x840940, 0x3122b2, 0x7, 0x5503, 0x0, 0x0, 0x0, 0x5503)
	/usr/local/go/src/net/http/client.go:398 +0xa0
main.main()
	/tmp/sandbox656600978/prog.go:15 +0xc0

Program exited: status 2.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions