From 88baf0492077ef8758d0385b9e2347c21385656c Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 29 May 2024 17:19:08 -0700 Subject: [PATCH] send always --- docs/src/api/params.md | 2 +- packages/playwright-core/src/server/fetch.ts | 2 +- packages/playwright-core/types/types.d.ts | 48 ++++++++++---------- tests/library/browsercontext-fetch.spec.ts | 4 +- tests/library/global-fetch.spec.ts | 2 +- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 524192e895..fe52329657 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -571,7 +571,7 @@ Whether to emulate network being offline. Defaults to `false`. Learn more about - `username` <[string]> - `password` <[string]> - `origin` ?<[string]> Restrain sending http credentials on specific origin (scheme://host:port). - - `send` ?<[WhenToSend]<"unauthorized"|"immediately">> This option only applies to the requests sent from corresponding [APIRequestContext] and does not affect requests sent from the browser. `'immediately'` - `Authorization` header with basic authentication credentials will be sent with the first API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. + - `send` ?<[WhenToSend]<"unauthorized"|"always">> This option only applies to the requests sent from corresponding [APIRequestContext] and does not affect requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. Credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication). If no origin is specified, the username and password are sent to any servers upon unauthorized responses. diff --git a/packages/playwright-core/src/server/fetch.ts b/packages/playwright-core/src/server/fetch.ts index f908d33013..0f87e0046b 100644 --- a/packages/playwright-core/src/server/fetch.ts +++ b/packages/playwright-core/src/server/fetch.ts @@ -159,7 +159,7 @@ export abstract class APIRequestContext extends SdkObject { } const credentials = this._getHttpCredentials(requestUrl); - if (credentials?.send === 'immediately') + if (credentials?.send === 'always') setBasicAuthorizationHeader(headers, credentials); const method = params.method?.toUpperCase() || 'GET'; diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 284616073c..eab37c1d00 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -13384,11 +13384,11 @@ export interface BrowserType { /** * This option only applies to the requests sent from corresponding {@link APIRequestContext} and does not affect - * requests sent from the browser. `'immediately'` - `Authorization` header with basic authentication credentials will - * be sent with the first API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) - * response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. + * requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be + * sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response + * with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. */ - send?: "unauthorized"|"immediately"; + send?: "unauthorized"|"always"; }; /** @@ -14922,11 +14922,11 @@ export interface AndroidDevice { /** * This option only applies to the requests sent from corresponding {@link APIRequestContext} and does not affect - * requests sent from the browser. `'immediately'` - `Authorization` header with basic authentication credentials will - * be sent with the first API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) - * response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. + * requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be + * sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response + * with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. */ - send?: "unauthorized"|"immediately"; + send?: "unauthorized"|"always"; }; /** @@ -15654,11 +15654,11 @@ export interface APIRequest { /** * This option only applies to the requests sent from corresponding {@link APIRequestContext} and does not affect - * requests sent from the browser. `'immediately'` - `Authorization` header with basic authentication credentials will - * be sent with the first API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) - * response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. + * requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be + * sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response + * with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. */ - send?: "unauthorized"|"immediately"; + send?: "unauthorized"|"always"; }; /** @@ -16812,11 +16812,11 @@ export interface Browser extends EventEmitter { /** * This option only applies to the requests sent from corresponding {@link APIRequestContext} and does not affect - * requests sent from the browser. `'immediately'` - `Authorization` header with basic authentication credentials will - * be sent with the first API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) - * response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. + * requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be + * sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response + * with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. */ - send?: "unauthorized"|"immediately"; + send?: "unauthorized"|"always"; }; /** @@ -17710,11 +17710,11 @@ export interface Electron { /** * This option only applies to the requests sent from corresponding {@link APIRequestContext} and does not affect - * requests sent from the browser. `'immediately'` - `Authorization` header with basic authentication credentials will - * be sent with the first API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) - * response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. + * requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be + * sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response + * with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. */ - send?: "unauthorized"|"immediately"; + send?: "unauthorized"|"always"; }; /** @@ -20379,11 +20379,11 @@ export interface HTTPCredentials { /** * This option only applies to the requests sent from corresponding {@link APIRequestContext} and does not affect - * requests sent from the browser. `'immediately'` - `Authorization` header with basic authentication credentials will - * be sent with the first API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) - * response with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. + * requests sent from the browser. `'always'` - `Authorization` header with basic authentication credentials will be + * sent with the each API request. `'unauthorized` - the credentials are only sent when 401 (Unauthorized) response + * with `WWW-Authenticate` header is received. Defaults to `'unauthorized'`. */ - send?: "unauthorized"|"immediately"; + send?: "unauthorized"|"always"; } export interface Geolocation { diff --git a/tests/library/browsercontext-fetch.spec.ts b/tests/library/browsercontext-fetch.spec.ts index e5006d2e91..b71869d504 100644 --- a/tests/library/browsercontext-fetch.spec.ts +++ b/tests/library/browsercontext-fetch.spec.ts @@ -438,7 +438,7 @@ it('should return error with wrong credentials', async ({ context, server }) => it('should support HTTPCredentials.sendImmediately for newContext', async ({ contextFactory, server }) => { it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30534' }); const context = await contextFactory({ - httpCredentials: { username: 'user', password: 'pass', origin: server.PREFIX.toUpperCase(), send: 'immediately' } + httpCredentials: { username: 'user', password: 'pass', origin: server.PREFIX.toUpperCase(), send: 'always' } }); { const [serverRequest, response] = await Promise.all([ @@ -462,7 +462,7 @@ it('should support HTTPCredentials.sendImmediately for newContext', async ({ con it('should support HTTPCredentials.sendImmediately for browser.newPage', async ({ contextFactory, server, browser }) => { it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30534' }); const page = await browser.newPage({ - httpCredentials: { username: 'user', password: 'pass', origin: server.PREFIX.toUpperCase(), send: 'immediately' } + httpCredentials: { username: 'user', password: 'pass', origin: server.PREFIX.toUpperCase(), send: 'always' } }); { const [serverRequest, response] = await Promise.all([ diff --git a/tests/library/global-fetch.spec.ts b/tests/library/global-fetch.spec.ts index c289794e9b..a2eb629dc5 100644 --- a/tests/library/global-fetch.spec.ts +++ b/tests/library/global-fetch.spec.ts @@ -157,7 +157,7 @@ it('should support WWW-Authenticate: Basic', async ({ playwright, server }) => { it('should support HTTPCredentials.sendImmediately', async ({ playwright, server }) => { it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30534' }); const request = await playwright.request.newContext({ - httpCredentials: { username: 'user', password: 'pass', origin: server.PREFIX.toUpperCase(), send: 'immediately' } + httpCredentials: { username: 'user', password: 'pass', origin: server.PREFIX.toUpperCase(), send: 'always' } }); { const [serverRequest, response] = await Promise.all([