test: content-length is recomputed for postBody override (#16169)

This commit is contained in:
Yury Semikhatsky 2022-08-02 13:55:52 -07:00 committed by GitHub
parent a2fc636f8e
commit 0bab5c60c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -173,6 +173,25 @@ it.describe('post data', () => {
expect((await serverRequest.postBody).toString('utf8')).toBe('doggo');
});
it('should compute content-length from post data', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/16027' });
it.fixme(browserName === 'firefox');
await page.goto(server.EMPTY_PAGE);
const data = 'a'.repeat(7500);
await page.route('**/*', route => {
const headers = route.request().headers();
headers['content-type'] = 'application/json';
route.continue({ postData: data, headers });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
page.evaluate(() => fetch('/sleep.zzz', { method: 'PATCH', body: 'birdy' }))
]);
expect((await serverRequest.postBody).toString('utf8')).toBe(data);
expect(serverRequest.headers['content-length']).toBe(String(data.length));
expect(serverRequest.headers['content-type']).toBe('application/json');
});
it('should amend method and post data', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
await page.route('**/*', route => {