Skip to content

Commit

Permalink
feat(fetch): send extra http headers (#8527)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Aug 28, 2021
1 parent bb5e44f commit 3727aa5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/server/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export async function playwrightFetch(context: BrowserContext, params: types.Fet
headers['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) {
Expand Down
16 changes: 16 additions & 0 deletions tests/browsercontext-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

0 comments on commit 3727aa5

Please sign in to comment.