I am doing
console.log("navigating");
var rsp = await fetch(params.url, {
credentials: "include", redirect: "manual", mode: "cors"
});
console.log(rsp);
rsp.headers.forEach(console.log);
console.log(rsp.headers.get('Location'));
console.log(rsp.headers.get('location'));
and the reponse headers from chrome dev tools:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:4400
Access-Control-Expose-Headers: Location
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 0
Date: Fri, 05 Oct 2018 12:48:21 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Location: http://localhost/test
gives
Response
body: (...)
bodyUsed: falseheaders:
Headers {}
ok: false
redirected: false
status: 0
statusText: ""
type: "opaqueredirect"
url: "..."
index.ts:161 null
index.ts:162 null
Is it not possible to get response headers out on redirect response?
Normally, fetch transparently follows HTTP-redirects, like 301, 302 etc.
An opaque-redirect filtered response is a filtered response whose type is "opaqueredirect", status is 0, status message is the empty byte sequence, header list is empty, body is null, and trailer is empty.
Is it not possible to get response headers out on redirect response?
No, it’s not possible. The requirements in the Fetch spec prevent it.
What the question shows is expected for manual
redirect mode: The headers object exposed to frontend JS is expected to be empty in responses to redirect: "manual"
requests.
When a request sets manual
redirect mode, the response type is opaqueredirect
. Info on the effects of that is at https://developer.mozilla.org/en-US/docs/Web/API/Response/type:
opaqueredirect
: The fetch request was made withredirect: "manual"
. The Response's status is 0, headers are empty, body is null and trailer is empty.
Those details in that MDN article are based directly on the following parts of the Fetch spec:
https://fetch.spec.whatwg.org/#concept-request-redirect-mode
A request has an associated redirect mode, which is
"follow"
,"error"
, or"manual"
.
…
"manual": Retrieves an opaque-redirect filtered response when a request is met with a redirect so that the redirect can be followed manually.
https://fetch.spec.whatwg.org/#concept-filtered-response-opaque-redirect
opaque-redirect filtered response is a filtered response whose type is
"opaqueredirect"
, status is0
, status message is the empty byte sequence, header list is empty, body is null
…
an opaque filtered response and an opaque-redirect filtered response are nearly indistinguishable from a network error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With