fix: accept post data for GET and HEAD http methods (#17008)

This commit is contained in:
Yury Semikhatsky 2022-09-01 08:36:08 -07:00 committed by GitHub
parent fafd9837ba
commit 27ffdcc944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 16 deletions

View File

@ -176,11 +176,7 @@ export abstract class APIRequestContext extends SdkObject {
requestUrl.searchParams.set(name, value);
}
let postData: Buffer | undefined;
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method))
postData = serializePostData(params, headers);
else if (params.postData || params.jsonData || params.formData || params.multipartData)
throw new Error(`Method ${method} does not accept post data`);
const postData = serializePostData(params, headers);
if (postData)
headers['content-length'] = String(postData.byteLength);
const controller = new ProgressController(metadata, this);

View File

@ -409,7 +409,7 @@ it('should return error with wrong credentials', async ({ context, server }) =>
expect(response2.status()).toBe(401);
});
for (const method of ['delete', 'patch', 'post', 'put']) {
for (const method of ['delete', 'get', 'head', 'patch', 'post', 'put']) {
it(`${method} should support post data`, async ({ context, server }) => {
const [request, response] = await Promise.all([
server.waitForRequest('/simple.json'),
@ -876,16 +876,6 @@ it('should throw nice error on unsupported data type', async function({ context,
expect(error.message).toContain(`Unexpected 'data' type`);
});
it('should throw when data passed for unsupported request', async function({ context, server }) {
const error = await context.request.fetch(server.EMPTY_PAGE, {
method: 'GET',
data: {
foo: 'bar'
}
}).catch(e => e);
expect(error.message).toContain(`Method GET does not accept post data`);
});
it('context request should export same storage state as context', async ({ context, page, server }) => {
server.setRoute('/setcookie.html', (req, res) => {
res.setHeader('Set-Cookie', ['a=b', 'c=d']);