cloudflare-cors-anywhere icon indicating copy to clipboard operation
cloudflare-cors-anywhere copied to clipboard

Simple 302 redirect makes the worker unusable

Open vladarte opened this issue 5 years ago • 4 comments

If server sets a 302 redirect rule to original links the script doesn't work. Try forexfactory.com as example. Is there a workaround?

vladarte avatar Mar 28 '20 10:03 vladarte

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

jimmywarting avatar May 14 '20 17:05 jimmywarting

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?

vadimkantorov avatar May 13 '21 11:05 vadimkantorov

{redirect : 'manual'} is useless apparently. At least proxy-side redirect would be useful...

vadimkantorov avatar May 13 '21 13:05 vadimkantorov

if you have any solutions feel free to do a pull request after testing it.

Zibri avatar Jul 14 '21 18:07 Zibri