Skip to content
Browse files

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 golang#27196

Change-Id: I0da86b61284fe394418b4b431495e715a037f335
Reviewed-by: Richard Musiol <>
Run-TryBot: Richard Musiol <>
TryBot-Result: Gobot Gobot <>
  • Loading branch information...
johanbrandhorst authored and Richard Musiol committed Aug 24, 2018
1 parent fdefaba commit ce536837d8e53f1bf0c7ef450d4580d19f7d6f52
Showing with 3 additions and 1 deletion.
  1. +3 −1 src/net/http/roundtrip_js.go
@@ -116,7 +116,9 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {

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

0 comments on commit ce53683

Please sign in to comment.
You can’t perform that action at this time.