Skip to content

Commit ce53683

Browse files
johanbrandhorstRichard Musiol
authored and
Richard Musiol
committed
net/http: ensure null body in Fetch response is not read
The Fetch API returns a null body if there is no response body, on browsers that support streaming the response body. This change ensures we check for both undefined and null bodies before attempting to read the body. Fixes #27196 Change-Id: I0da86b61284fe394418b4b431495e715a037f335 Reviewed-on: https://go-review.googlesource.com/131236 Reviewed-by: Richard Musiol <[email protected]> Run-TryBot: Richard Musiol <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent fdefaba commit ce53683

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/net/http/roundtrip_js.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
116116

117117
b := result.Get("body")
118118
var body io.ReadCloser
119-
if b != js.Undefined() {
119+
// The body is undefined when the browser does not support streaming response bodies (Firefox),
120+
// and null in certain error cases, i.e. when the request is blocked because of CORS settings.
121+
if b != js.Undefined() && b != js.Null() {
120122
body = &streamReader{stream: b.Call("getReader")}
121123
} else {
122124
// Fall back to using ArrayBuffer

0 commit comments

Comments
 (0)