]> Cypherpunks.ru repositories - gostls13.git/commitdiff
net/http: support configuring redirect fetch option
authorJohan Brandhorst <johan.brandhorst@gmail.com>
Sun, 3 Mar 2019 20:16:13 +0000 (20:16 +0000)
committerRichard Musiol <neelance@gmail.com>
Tue, 5 Mar 2019 14:19:59 +0000 (14:19 +0000)
Adds a magic header value that is translated to the
Fetch API redirect option, following existing practices.

Updates #26769

Change-Id: Iaf1c9f710de63ea941a360b73f1b4bb725331a35
Reviewed-on: https://go-review.googlesource.com/c/go/+/164666
Reviewed-by: Richard Musiol <neelance@gmail.com>
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/net/http/roundtrip_js.go

index 1e38b908d387e7e6b5d26d6e9724f6c6feac2496..21d19515fac1632630592db2193146fd8ddf6a91 100644 (file)
@@ -33,6 +33,14 @@ const jsFetchMode = "js.fetch:mode"
 // Reference: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters
 const jsFetchCreds = "js.fetch:credentials"
 
+// jsFetchRedirect is a Request.Header map key that, if present,
+// signals that the map entry is actually an option to the Fetch API redirect setting.
+// Valid values are: "follow", "error", "manual"
+// The default is "follow".
+//
+// Reference: https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters
+const jsFetchRedirect = "js.fetch:redirect"
+
 // RoundTrip implements the RoundTripper interface using the WHATWG Fetch API.
 func (t *Transport) RoundTrip(req *Request) (*Response, error) {
        if useFakeNetwork() {
@@ -60,6 +68,10 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) {
                opt.Set("mode", h)
                req.Header.Del(jsFetchMode)
        }
+       if h := req.Header.Get(jsFetchRedirect); h != "" {
+               opt.Set("redirect", h)
+               req.Header.Del(jsFetchRedirect)
+       }
        if ac != js.Undefined() {
                opt.Set("signal", ac.Get("signal"))
        }