cloudflare-cors-anywhere
cloudflare-cors-anywhere copied to clipboard
Simple 302 redirect makes the worker unusable
If server sets a 302 redirect rule to original links the script doesn't work. Try forexfactory.com as example. Is there a workaround?
I think it's nice that the browser makes the redirect instead of it being done at server-side, like many other proxies - it gives you more control over the request that is being done.
however I notice when a redirect happens to a relative path like this one:
var proxy = 'https://test.cors.workers.dev/?'
var url = 'https://httpbin.org/cookies/set/key/value'
fetch(proxy + url)
it will redirect to https://test.cors.workers.dev/get
but if i would be able to do it manually, then i could potentially fix it and and do the redirect as well as reading the forbidden set cookie header:
var proxy = 'https://test.cors.workers.dev/?'
var url = 'https://httpbin.org/cookies/set/key/value'
fetch(proxy + url, { follow: 'manual' }).then(res => {
// read the forbidden headers:
var headers = res.headers.get('cors-received-headers')
headers = new Headers(JSON.parse(headers))
console.log(headers.get('set-cookie'))
// handle the redirect:
var base = url
var location = new URL(res.headers.get('location'), base)
fetch(proxy + location)
})
but the response is a opaqueredirect and i can't read anything
Same problem. I tried to download GitHub zipballs with my deployment of this CORS proxy: https://github.com/vadimkantorov/busyidetest/archive/refs/heads/master.zip. This redirects to https://codeload.github.com/vadimkantorov/busyidetest/zip/refs/heads/master, and the browser runs this second request without CORS proxy.
How do I handle the redirect manually so that I can make the redirected request with CORS proxy as well? Should I try {redirect : 'manual'} parameter for fetch call?
{redirect : 'manual'} is useless apparently. At least proxy-side redirect would be useful...
if you have any solutions feel free to do a pull request after testing it.