我正在使用CORS Unblock扩展名,并注意到某些POST请求仍未通过预检检查。
这是因为,除非响应具有必需的Access-Control-Allow-Origin
标头并且状态代码为200 OK
,否则飞行前检查将失败。
结果为net::ERR_BLOCKED_BY_CLIENT
。
chrome.webRequest.onBeforeRequest.addListener(
e => {
if(e.method == "OPTIONS")
return {cancel: true};
},
{urls: ["<all_urls>"]},
["blocking", "extraHeaders"]
);
重定向请求将导致Redirect is not allowed for a preflight request
。
chrome.webRequest.onBeforeRequest.addListener(
e => {
if(e.method == "OPTIONS")
return {redirectUrl: "javascript:"};
},
{urls: ["<all_urls>"]},
["blocking", "extraHeaders"]
);
我可以阻止OPTIONS
请求并返回200 OK
状态码吗?
感谢您的时间。