mirror of
https://github.com/golang/go
synced 2024-11-19 11:44:45 -07:00
net/http: fix build errors on js/wasm target
The in-progress WASM port does not yet have sufficient automatic
testing performed against it, so these errors slipped through when
adding the new Fetch API backed http.Roundtripper.
Updates #25506
Change-Id: I84c5832452e3e6067a02d926f67d01aaca66b837
GitHub-Last-Rev: 064062b5fd
GitHub-Pull-Request: golang/go#25714
Reviewed-on: https://go-review.googlesource.com/116076
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
446d76e62d
commit
fb5279cc45
@ -12,13 +12,13 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"syscall/js"
|
"syscall/js"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RoundTrip implements the RoundTripper interface using the WHATWG Fetch API.
|
// RoundTrip implements the RoundTripper interface using the WHATWG Fetch API.
|
||||||
func (*Transport) RoundTrip(req *Request) (*Response, error) {
|
func (t *Transport) RoundTrip(req *Request) (*Response, error) {
|
||||||
if useFakeNetwork() {
|
if useFakeNetwork() {
|
||||||
return t.roundTrip(req)
|
return t.roundTrip(req)
|
||||||
}
|
}
|
||||||
@ -134,10 +134,12 @@ func (*Transport) RoundTrip(req *Request) (*Response, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errClosed = errors.New("net/http: reader is closed")
|
||||||
|
|
||||||
// useFakeNetwork is used to determine whether the request is made
|
// useFakeNetwork is used to determine whether the request is made
|
||||||
// by a test and should be made to use the fake in-memory network.
|
// by a test and should be made to use the fake in-memory network.
|
||||||
func useFakeNetwork() bool {
|
func useFakeNetwork() bool {
|
||||||
return len(os.Args) > 0 && path.Base(os.Args[0]) == "node"
|
return len(os.Args) > 0 && strings.HasSuffix(os.Args[0], ".test")
|
||||||
}
|
}
|
||||||
|
|
||||||
// streamReader implements an io.ReadCloser wrapper for ReadableStream.
|
// streamReader implements an io.ReadCloser wrapper for ReadableStream.
|
||||||
|
Loading…
Reference in New Issue
Block a user