Fetch: Disable follow redirect

Created on 5 May 2015  Â·  10Comments  Â·  Source: github/fetch

Quote from standard:

A request has an associated redirect mode, which is one of "follow", "error", and "manual". Unless stated otherwise, it is "follow".

A request has an associated redirect count. Unless stated otherwise, it is zero.

Most helpful comment

This is a nice addition to the Fetch API, but we won't be able to polyfill it with XMLHttpRequest. The browser navigates all redirects before returning a result, so there is no opportunity to interrupt the redirect flow.

If the response has an HTTP status code of 301, 302, 303, 307, or 308…Set the request URL to the URL conveyed by the Location header…transparently follow the redirect…

—XMLHttpRequest specification

All 10 comments

I don't think this is going to be possible to polyfill on top of XHR.

I don't think this is exposed in the API anyway. Those sentences have no bearing on window.fetch.

@dgraham Hi, can you reopen this issue?

https://www.chromestatus.com/features/4614142321229824

https://fetch.spec.whatwg.org/#requestredirect

JS use:

fetch(new Request(url, {redirect: 'manual'}))

This is a nice addition to the Fetch API, but we won't be able to polyfill it with XMLHttpRequest. The browser navigates all redirects before returning a result, so there is no opportunity to interrupt the redirect flow.

If the response has an HTTP status code of 301, 302, 303, 307, or 308…Set the request URL to the URL conveyed by the Location header…transparently follow the redirect…

—XMLHttpRequest specification

That's right but I think we can at least mimic redirect: error using responseURL attribute, (unfortunately) after redirection.

@SaschaNaz We _could_ make a clumsy support for redirect: error, but that would only provide a partial and imperfect support for the redirect setting. I'd rather that we don't support this at all in the polyfill.

@mislav That's reasonable, thanks :)

Is this difference from the standard documented anywhere?

@axelson I don't think so. You're welcome to add it to our documentation in the "gh-pages" branch seen here when published.

Yeyo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

codeashian picture codeashian  Â·  3Comments

hannesvdvreken picture hannesvdvreken  Â·  4Comments

poppinlp picture poppinlp  Â·  4Comments

indranildutta06 picture indranildutta06  Â·  3Comments

gkatsanos picture gkatsanos  Â·  4Comments