Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(fetch): send extra http headers (#8527)
Yury Semikhatsky3727aa5b675b
diff --git a/src/server/fetch.ts b/src/server/fetch.tsindex 4e9fd5317b..0f724c3323 100644--- a/src/server/fetch.ts+++ b/src/server/fetch.ts@@ -32,6 +32,11 @@ export async function playwrightFetch(context: BrowserContext, params: types.Fetheaders['accept'] ??= '*/*';headers['accept-encoding'] ??= 'gzip,deflate';+ if (context._options.extraHTTPHeaders) {+ for (const {name, value} of context._options.extraHTTPHeaders)+ headers[name.toLowerCase()] = value;+ }+const method = params.method?.toUpperCase() || 'GET';let agent;if (context._options.proxy) {diff --git a/tests/browsercontext-fetch.spec.ts b/tests/browsercontext-fetch.spec.tsindex 489bb49e13..d97dcf4cee 100644--- a/tests/browsercontext-fetch.spec.ts+++ b/tests/browsercontext-fetch.spec.ts@@ -313,3 +313,19 @@ it('should propagate custom headers with redirects', async ({context, server}) =expect(req3.headers['foo']).toBe('bar');});+it('should propagate extra http headers with redirects', async ({context, server}) => {+ server.setRedirect('/a/redirect1', '/b/c/redirect2');+ server.setRedirect('/b/c/redirect2', '/simple.json');+ await context.setExtraHTTPHeaders({ 'My-Secret': 'Value' });+ const [req1, req2, req3] = await Promise.all([+ server.waitForRequest('/a/redirect1'),+ server.waitForRequest('/b/c/redirect2'),+ server.waitForRequest('/simple.json'),+ // @ts-expect-error+ context._fetch(`${server.PREFIX}/a/redirect1`),+ ]);+ expect(req1.headers['my-secret']).toBe('Value');+ expect(req2.headers['my-secret']).toBe('Value');+ expect(req3.headers['my-secret']).toBe('Value');+});+