Chrome cancels CORS XHR upon HTTP 302 redirect

前端 未结 4 1019
梦毁少年i
梦毁少年i 2020-11-27 04:42

It looks like according to the CORS Spec, GET and POST requests should transparently follow 302 redirects. But Chrome is canceling my request.

Here\'s the JS that d

4条回答
  •  迷失自我
    2020-11-27 05:01

    The answers in here are mixed, hinting on certain settings in code etc. which may solve the redirect problem with CORS, but the CORS spec clearly specifies when such CORS redirects will fail/pass : As per the spec, browsers should

    1. Allows 3XX redirect , if the request to the redirected resource doesn't require pre-flight check (simple CORS requests without custom header for example). See https://www.w3.org/TR/cors/#simple-cross-origin-request-0

    If the manual redirect flag is unset and the response has an HTTP status code of 301, 302, 303, 307, or 308 Apply the redirect steps

    1. Don't allow 3XX redirect, if the request to redirected resource requires pre-flight check. See https://www.w3.org/TR/cors/#cross-origin-request-with-preflight-0

    If the response has an HTTP status code of 301, 302, 303, 307, or 308 Apply the cache and network error steps.

    I have explored various CORS scenarios in github repo: https://github.com/monmohan/cors-experiment.

    This specific issue with failed redirect can also be easily reproduced in isolation by the bundle here: https://github.com/monmohan/cors-experiment/tree/master/issue

提交回复
热议问题