-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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 always send httpCredentials in APIRequestContext #30534
Comments
Do you know if other API testing frameworks do that? Having a list of frameworks would help as we would treat it as feature parity. |
Can't claim to know all the API testing frameworks, so I have likely missed some (maybe including some that are in common use), but here's what some of them do:
I could try more, but after four in a row behaving the same way, I stopped. It looks to me like the "send the headers immediately without waiting for a 401" behavior is the default; I didn't find any that followed Playwright's behavior of waiting for the 401. (It's remotely possible that I'm mistaken about what autokin does, as I didn't actually test it, only read the source code). |
Looking at Cypress their docs about api testing say options for auth are defined here, which has a parameter
sounds like a good example to follow, obviously playwright should probably have |
🚀 Feature Request
The
httpCredendtials
feature on APIRequestContext works by lookiing for an HTTP 401 response and sending the credentials only if the 401 response contains a WWW-Authenticate header. (And then, only if the header starts with "Basic" — digest authentication is apparently not supported yet).For most servers, this works fine. But there are some servers out there that do not send a 401 when a request lacks authentication, but instead send a 403 or other response. The HTTP/1.1 spec, RFC 7235, states (on page 4, you may need to scroll down) that servers SHOULD send a 401 when a request lacks credentials, but SHOULD is not MUST and not all servers choose to send a 401.
In order to make it easier to send authenticated GET requests to servers that don't send 401 errors, it would be nice to have an option in the
httpCredentials
object calledalwaysSendCredentials
or perhaps justalways
for short. This would send theAuthorization: Basic Zm9vOmJhcg==
header on the first request, rather than waiting for a 401 and sending a second request with the header. If the optionalorigin
property was given, thenalways
would add the credentials only to requests going to that origin.Example
Motivation
Some people are dealing with servers that expect Authorization headers in the first request. Others are dealing with tests in a high-latency environment, where each HTTP request might take a second or two to receive a response. If each authenticated request has to be sent twice, that can add up to a lot of unnecessarily-wasted time.
In the case of servers that expect an Authorization header the first time, that's not what the HTTP spec says they SHOULD do... but SHOULD is not MUST, and a server that does not send 401 is still in compliance with the spec. It would be nice if
httpCredentials
could be easily used to send requests to such servers.In the case of high-latency environments, being able to tell Playwright to always send credentials no matter what would result in tests that run faster.
In both cases, you can work around this by adding an Authorization header to
extraHTTPHeaders
so that it will be sent every time, but this is not always desirable as some requests might be going to servers (say, GitHub) where you don't want to send the credentials for your private API service. So having thealways: true
option available onhttpCredentials
and having it honororigin
would be the best solution to both of these use cases.The text was updated successfully, but these errors were encountered: