From: Johan Brandhorst Date: Sun, 3 Mar 2019 20:16:13 +0000 (+0000) Subject: net/http: support configuring redirect fetch option X-Git-Tag: go1.13beta1~1218 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=94cbfc2f7f6b375426381c81d8efe78b12e058c3;p=gostls13.git 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 Reviewed-by: Agniva De Sarker Run-TryBot: Agniva De Sarker TryBot-Result: Gobot Gobot --- 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")) }