mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix: accept post data for GET and HEAD http methods (#17008)
This commit is contained in:
parent
fafd9837ba
commit
27ffdcc944
@ -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);
|
||||
|
@ -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']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user