mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-01 16:49:20 +03:00
fix(fetch): post data for delete request (#10019)
This commit is contained in:
parent
bde5c2590e
commit
bce9a8187d
@ -16,6 +16,9 @@ context cookies from the response. The method will automatically follow redirect
|
|||||||
### param: APIRequestContext.delete.url = %%-fetch-param-url-%%
|
### param: APIRequestContext.delete.url = %%-fetch-param-url-%%
|
||||||
### option: APIRequestContext.delete.params = %%-fetch-option-params-%%
|
### option: APIRequestContext.delete.params = %%-fetch-option-params-%%
|
||||||
### option: APIRequestContext.delete.headers = %%-fetch-option-headers-%%
|
### option: APIRequestContext.delete.headers = %%-fetch-option-headers-%%
|
||||||
|
### option: APIRequestContext.delete.data = %%-fetch-option-data-%%
|
||||||
|
### option: APIRequestContext.delete.form = %%-fetch-option-form-%%
|
||||||
|
### option: APIRequestContext.delete.multipart = %%-fetch-option-multipart-%%
|
||||||
### option: APIRequestContext.delete.timeout = %%-fetch-option-timeout-%%
|
### option: APIRequestContext.delete.timeout = %%-fetch-option-timeout-%%
|
||||||
### option: APIRequestContext.delete.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
### option: APIRequestContext.delete.failOnStatusCode = %%-fetch-option-failonstatuscode-%%
|
||||||
### option: APIRequestContext.delete.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
### option: APIRequestContext.delete.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
|
||||||
|
@ -84,7 +84,7 @@ export class FetchRequest extends ChannelOwner<channels.FetchRequestChannel, cha
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async delete(url: string, options?: RequestWithoutBodyOptions): Promise<FetchResponse> {
|
async delete(url: string, options?: RequestWithBodyOptions): Promise<FetchResponse> {
|
||||||
return this.fetch(url, {
|
return this.fetch(url, {
|
||||||
...options,
|
...options,
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
|
@ -143,7 +143,7 @@ export abstract class FetchRequest extends SdkObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let postData;
|
let postData;
|
||||||
if (['POST', 'PUT', 'PATCH'].includes(method))
|
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(method))
|
||||||
postData = serializePostData(params, headers);
|
postData = serializePostData(params, headers);
|
||||||
else if (params.postData || params.jsonData || params.formData || params.multipartData)
|
else if (params.postData || params.jsonData || params.formData || params.multipartData)
|
||||||
throw new Error(`Method ${method} does not accept post data`);
|
throw new Error(`Method ${method} does not accept post data`);
|
||||||
|
37
packages/playwright-core/types/types.d.ts
vendored
37
packages/playwright-core/types/types.d.ts
vendored
@ -11747,11 +11747,25 @@ export interface APIRequestContext {
|
|||||||
* @param options
|
* @param options
|
||||||
*/
|
*/
|
||||||
delete(url: string, options?: {
|
delete(url: string, options?: {
|
||||||
|
/**
|
||||||
|
* Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and
|
||||||
|
* `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` header will
|
||||||
|
* be set to `application/octet-stream` if not explicitly set.
|
||||||
|
*/
|
||||||
|
data?: string|Buffer|Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
|
* Whether to throw on response codes other than 2xx and 3xx. By default response object is returned for all status codes.
|
||||||
*/
|
*/
|
||||||
failOnStatusCode?: boolean;
|
failOnStatusCode?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an object that will be serialized as html form using `application/x-www-form-urlencoded` encoding and sent as
|
||||||
|
* this request body. If this parameter is specified `content-type` header will be set to
|
||||||
|
* `application/x-www-form-urlencoded` unless explicitly provided.
|
||||||
|
*/
|
||||||
|
form?: { [key: string]: string|number|boolean; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to set HTTP headers.
|
* Allows to set HTTP headers.
|
||||||
*/
|
*/
|
||||||
@ -11762,6 +11776,29 @@ export interface APIRequestContext {
|
|||||||
*/
|
*/
|
||||||
ignoreHTTPSErrors?: boolean;
|
ignoreHTTPSErrors?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides an object that will be serialized as html form using `multipart/form-data` encoding and sent as this request
|
||||||
|
* body. If this parameter is specified `content-type` header will be set to `multipart/form-data` unless explicitly
|
||||||
|
* provided. File values can be passed either as [`fs.ReadStream`](https://nodejs.org/api/fs.html#fs_class_fs_readstream)
|
||||||
|
* or as file-like object containing file name, mime-type and its content.
|
||||||
|
*/
|
||||||
|
multipart?: { [key: string]: string|number|boolean|ReadStream|{
|
||||||
|
/**
|
||||||
|
* File name
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File type
|
||||||
|
*/
|
||||||
|
mimeType: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File content
|
||||||
|
*/
|
||||||
|
buffer: Buffer;
|
||||||
|
}; };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query parameters to be send with the URL.
|
* Query parameters to be send with the URL.
|
||||||
*/
|
*/
|
||||||
|
@ -413,18 +413,20 @@ it('should return error with wrong credentials', async ({ context, server }) =>
|
|||||||
expect(response2.status()).toBe(401);
|
expect(response2.status()).toBe(401);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support post data', async ({ context, server }) => {
|
for (const method of ['delete', 'patch', 'post', 'put']) {
|
||||||
const [request, response] = await Promise.all([
|
it(`${method} should support post data`, async ({ context, server }) => {
|
||||||
server.waitForRequest('/simple.json'),
|
const [request, response] = await Promise.all([
|
||||||
context.request.post(`${server.PREFIX}/simple.json`, {
|
server.waitForRequest('/simple.json'),
|
||||||
data: 'My request'
|
context.request[method](`${server.PREFIX}/simple.json`, {
|
||||||
})
|
data: 'My request'
|
||||||
]);
|
})
|
||||||
expect(request.method).toBe('POST');
|
]);
|
||||||
expect((await request.postBody).toString()).toBe('My request');
|
expect(request.method).toBe(method.toUpperCase());
|
||||||
expect(response.status()).toBe(200);
|
expect((await request.postBody).toString()).toBe('My request');
|
||||||
expect(request.url).toBe('/simple.json');
|
expect(response.status()).toBe(200);
|
||||||
});
|
expect(request.url).toBe('/simple.json');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
it('should add default headers', async ({ context, server, page }) => {
|
it('should add default headers', async ({ context, server, page }) => {
|
||||||
const [request] = await Promise.all([
|
const [request] = await Promise.all([
|
||||||
|
Loading…
Reference in New Issue
Block a user