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();
|
request.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const headers: HeadersObject = { ...options.headers };
|
const headers = { ...options.headers };
|
||||||
removeHeader(headers, `cookie`);
|
removeHeader(headers, `cookie`);
|
||||||
|
|
||||||
// HTTP-redirect fetch step 13 (https://fetch.spec.whatwg.org/#http-redirect-fetch)
|
// 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`);
|
removeHeader(headers, `content-type`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const redirectOptions: SendRequestOptions = {
|
const redirectOptions: SendRequestOptions = {
|
||||||
method,
|
method,
|
||||||
headers,
|
headers,
|
||||||
|
|
@ -331,6 +332,10 @@ export abstract class APIRequestContext extends SdkObject {
|
||||||
request.destroy();
|
request.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (headers['host'])
|
||||||
|
headers['host'] = locationURL.host;
|
||||||
|
|
||||||
notifyRequestFinished();
|
notifyRequestFinished();
|
||||||
fulfill(this._sendRequest(progress, locationURL, redirectOptions, postData));
|
fulfill(this._sendRequest(progress, locationURL, redirectOptions, postData));
|
||||||
request.destroy();
|
request.destroy();
|
||||||
|
|
|
||||||
|
|
@ -1123,4 +1123,33 @@ it('should support set-cookie with SameSite and without Secure attribute over HT
|
||||||
expect(cookie.sameSite).toBe(value);
|
expect(cookie.sameSite).toBe(value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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 a new issue