Merge branch 'link2xt/redirect-follow' into 'master'

Follow redirects with `fetch`

Closes #85

See merge request rysiekpl/libresilient!29
master
Michał "rysiek" Woźniak 2024-10-19 21:51:26 +00:00
commit 4b9f4fb2ec
1 zmienionych plików z 17 dodań i 1 usunięć

Wyświetl plik

@ -1012,7 +1012,23 @@ let initFromRequest = (req) => {
//mode: req.mode, TODO: commented out because mode: navigate is haram in service worker, it seems
//credentials: req.credentials, TODO: commented out because credentials: "include" is haram if the Access-Control-Allow-Origin header is '*'
cache: req.cache,
redirect: req.redirect,
// `req.redirect` is usually "manual":
// <https://stackoverflow.com/questions/42716082/fetch-api-whats-the-use-of-redirect-manual>
//
// It is not useful for fetch() requests
// as on redirect it returns a response with "opaqueredirect" type
// 0 response code and no way to get actual location:
// <https://stackoverflow.com/questions/39735496/redirect-after-a-fetch-post-call>.
//
// This approach has a drawback of not changing the URL
// in a browser when following the redirect for the page
// (in contrast to some resource like an image where it does not matter),
// but there is no better option until browsers provide some way
// to access redirect responses such as the one
// proposed in <https://github.com/whatwg/fetch/issues/601>.
redirect: "follow",
referrer: req.referrer,
integrity: req.integrity
}