feat(fetch): send extra http headers (#8527)
This commit is contained in:
parent
bb5e44fbc4
commit
3727aa5b67
|
|
@ -32,6 +32,11 @@ export async function playwrightFetch(context: BrowserContext, params: types.Fet
|
||||||
headers['accept'] ??= '*/*';
|
headers['accept'] ??= '*/*';
|
||||||
headers['accept-encoding'] ??= 'gzip,deflate';
|
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';
|
const method = params.method?.toUpperCase() || 'GET';
|
||||||
let agent;
|
let agent;
|
||||||
if (context._options.proxy) {
|
if (context._options.proxy) {
|
||||||
|
|
|
||||||
|
|
@ -313,3 +313,19 @@ it('should propagate custom headers with redirects', async ({context, server}) =
|
||||||
expect(req3.headers['foo']).toBe('bar');
|
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');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue