Commit 94cbfc2f authored by Johan Brandhorst's avatar Johan Brandhorst Committed by Richard Musiol

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/+/164666Reviewed-by: default avatarRichard Musiol <neelance@gmail.com>
Reviewed-by: default avatarAgniva De Sarker <agniva.quicksilver@gmail.com>
Run-TryBot: Agniva De Sarker <agniva.quicksilver@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 29bc4f12
......@@ -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"))
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment