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

[Feature] Option to not follow redirects in the requests API #12911

Closed
Meemaw opened this issue Mar 20, 2022 · 7 comments · Fixed by #17227
Closed

[Feature] Option to not follow redirects in the requests API #12911

Meemaw opened this issue Mar 20, 2022 · 7 comments · Fixed by #17227

Comments

@Meemaw
Copy link

Meemaw commented Mar 20, 2022

The request fixture methods seems to follow the redirects by default. It would be great if there was an option to disable this behaviour.

const response = await request.get('http://localhost:3000/url', { followRedirects: false })
expect(response.status()).toBe(302)
expect(response.headers()['Location']).toBe('/login')
@mxschmitt
Copy link
Member

mxschmitt commented Apr 14, 2022

@Meemaw what is the use-case for it? this would help us to prioritise it.

@Meemaw
Copy link
Author

Meemaw commented Apr 15, 2022

@mxschmitt We're using Playwright to test an application with server side rendering. Some of the tests are testing that our server correctly redirects you based on your permissions (e.g redirection to /login when you visit some authenticated page).

We could test that by just navigating to that page using page.goto, and assert that we are on the expected page, but that is not the same. That would have passed even if the navigation client side. In our case, we want to test the server returns status code 302 and appropriate redirect. These tests are also much "cheaper" as there might be a lot of them.

We currently use node-fetch to test this, but would be great if we could use builtin stuff.

@raimohanska
Copy link

We have a similar use case and would greatly appreciate this. We mostly use page.request which is an APIRequestContext object.

@franzvezuli
Copy link

One use case that I use is:

-- Inspect the first call has a status of 302
-- Inspect the location header is correct

@vincenzo-gasparo
Copy link
Contributor

I have similar use cases too, I often need to check the redirect location for some auth routes and this feature would be very useful. Currently we are using another request module to handle this use case.

@jessfraz
Copy link

jessfraz commented Jul 11, 2022

Yes want to check the set-cookie header on a 302 redirect to intercept it and set it via playwright since chromium blocks third-party cookies in incognito mode (aka playwright default settings)

using fetch currently as a work around

@mcdehaan
Copy link

Same as the people above me. I'm testing for the 302 status, location in the header and correct cookies. My workaround is using Axios but I try to replace it entirely with Playwright.

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

Successfully merging a pull request may close this issue.

9 participants