mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 14:11:50 +03:00
fix(fetch): update host header on redirect (#26750)
Fixes https://github.com/microsoft/playwright/issues/26743
This commit is contained in:
parent
5c72cbdb23
commit
501ed32856
@ -291,7 +291,7 @@ export abstract class APIRequestContext extends SdkObject {
|
||||
request.destroy();
|
||||
return;
|
||||
}
|
||||
const headers: HeadersObject = { ...options.headers };
|
||||
const headers = { ...options.headers };
|
||||
removeHeader(headers, `cookie`);
|
||||
|
||||
// HTTP-redirect fetch step 13 (https://fetch.spec.whatwg.org/#http-redirect-fetch)
|
||||
@ -308,6 +308,7 @@ export abstract class APIRequestContext extends SdkObject {
|
||||
removeHeader(headers, `content-type`);
|
||||
}
|
||||
|
||||
|
||||
const redirectOptions: SendRequestOptions = {
|
||||
method,
|
||||
headers,
|
||||
@ -331,6 +332,10 @@ export abstract class APIRequestContext extends SdkObject {
|
||||
request.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
if (headers['host'])
|
||||
headers['host'] = locationURL.host;
|
||||
|
||||
notifyRequestFinished();
|
||||
fulfill(this._sendRequest(progress, locationURL, redirectOptions, postData));
|
||||
request.destroy();
|
||||
|
@ -1124,3 +1124,32 @@ it('should support set-cookie with SameSite and without Secure attribute over HT
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should update host header on redirect', async ({ context, server }) => {
|
||||
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/26743' });
|
||||
let redirectCount = 0;
|
||||
server.setRoute('/redirect', (req, res) => {
|
||||
redirectCount++;
|
||||
const path = (req.headers.host === new URL(server.PREFIX).host) ? '/redirect' : '/test';
|
||||
res.writeHead(302, {
|
||||
host: new URL(server.CROSS_PROCESS_PREFIX).host,
|
||||
location: server.CROSS_PROCESS_PREFIX + path,
|
||||
});
|
||||
res.end();
|
||||
});
|
||||
server.setRoute('/test', (req, res) => {
|
||||
res.writeHead(200, {
|
||||
'content-type': 'text/plain',
|
||||
});
|
||||
res.end('Hello!');
|
||||
});
|
||||
const reqPromise = server.waitForRequest('/test');
|
||||
const response = await context.request.get(server.PREFIX + '/redirect', {
|
||||
headers: { host: new URL(server.PREFIX).host }
|
||||
});
|
||||
expect(redirectCount).toBe(2);
|
||||
await expect(response).toBeOK();
|
||||
expect(await response.text()).toBe('Hello!');
|
||||
|
||||
expect((await reqPromise).headers.host).toBe(new URL(server.CROSS_PROCESS_PREFIX).host);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user