Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple 302 redirect makes the worker unusable #11

Open
vladarte opened this issue Mar 28, 2020 · 4 comments
Open

Simple 302 redirect makes the worker unusable #11

vladarte opened this issue Mar 28, 2020 · 4 comments

Comments

@vladarte
Copy link

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

@jimmywarting
Copy link
Contributor

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

@vadimkantorov
Copy link

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
Copy link

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

@Zibri
Copy link
Owner

Zibri commented Jul 14, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants