Follow subrequest redirects with cookies

Hi,

A subrequest in Workers follows redirects by default and this is the desired behaviour for our use case.
However, the remote server may send the redirect with a cookie and only if the redirect is followed with the cookie does the remote server responds with 200. Else (no cookie), the remote server sends a 403.
This behaviour by the remote server is probably intended to disallow non-browser clients or something.

My question: is there a way to follow subrequest redirects with cookies?
Would this do the trick:

  • Do the subrequest fetch with redirect: manual so not to follow redirects
  • If response.redirected, get the cookies from the response headers and put these in the next request’s headers

If yes: is there an easier way? :wink:

Currently, with Workers, no. You’ll have to manually extract the cookie(s) from the Set-Cookie header field and include them with your second request.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.