feat(fetch): send extra http headers (#8527)

This commit is contained in:
Yury Semikhatsky 2021-08-27 23:47:21 -07:00 committed by GitHub
parent bb5e44fbc4
commit 3727aa5b67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -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) {

View File

@ -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');
});