Skip to content

Commit b5ed6ec

Browse files
johanbrandhorstbradfitz
authored andcommitted
[release-branch.go1.11] 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 #27424 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]> (cherry picked from commit ce53683) Reviewed-on: https://go-review.googlesource.com/136915
1 parent f2113d9 commit b5ed6ec

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/net/http/roundtrip_js.go

Lines changed: 3 additions & 1 deletion
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)