diff options
| author | Johan Brandhorst <johan.brandhorst@gmail.com> | 2019-03-03 20:16:13 +0000 |
|---|---|---|
| committer | Richard Musiol <neelance@gmail.com> | 2019-03-05 14:19:59 +0000 |
| commit | 94cbfc2f7f6b375426381c81d8efe78b12e058c3 (patch) | |
| tree | 0ec0c103529863c5ed90921292dd12ff607ec1ac /src | |
| parent | 29bc4f12581d836a96139c924f16a4987324edd1 (diff) | |
| download | go-94cbfc2f7f6b375426381c81d8efe78b12e058c3.tar.xz | |
net/http: support configuring redirect fetch option
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/net/http/roundtrip_js.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/net/http/roundtrip_js.go b/src/net/http/roundtrip_js.go index 1e38b908d3..21d19515fa 100644 --- a/src/net/http/roundtrip_js.go +++ b/src/net/http/roundtrip_js.go @@ -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")) } |
