1
0
mirror of https://github.com/golang/go synced 2024-11-26 22:21:27 -07:00

net/http: perform streaming body feature detection once per process

As far a I can tell, there's currently no situation where this feature
detection will report a different result per request, so default to
doing once per process until there's evidence that doing it more often
is worthwhile.

Change-Id: I567d3dbd847af2f49f2e83cd9eb0ae61d82c1f83
Reviewed-on: https://go-review.googlesource.com/c/go/+/513459
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This commit is contained in:
Dmitri Shuralyov 2023-07-23 14:19:57 -04:00
parent a8a6f90a23
commit 8488309192

View File

@ -12,6 +12,7 @@ import (
"io"
"strconv"
"strings"
"sync"
"syscall/js"
)
@ -57,7 +58,7 @@ var jsFetchDisabled = js.Global().Get("process").Type() == js.TypeObject &&
// Determine whether the JS runtime supports streaming request bodies.
// Courtesy: https://developer.chrome.com/articles/fetch-streaming-requests/#feature-detection
func supportsPostRequestStreams() bool {
var supportsPostRequestStreams = sync.OnceValue(func() bool {
requestOpt := js.Global().Get("Object").New()
requestBody := js.Global().Get("ReadableStream").New()
@ -85,7 +86,7 @@ func supportsPostRequestStreams() bool {
hasContentTypeHeader := requestObject.Get("headers").Call("has", "Content-Type").Bool()
return duplexCalled && !hasContentTypeHeader
}
})
// RoundTrip implements the RoundTripper interface using the WHATWG Fetch API.
func (t *Transport) RoundTrip(req *Request) (*Response, error) {