Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 10 additions & 34 deletions docs/src/api/class-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,6 @@ request is issued to a redirected url.

An object with all the request HTTP headers associated with this request. The header names are lower-cased.

## async method: Request.body
* since: v1.57
- returns: <[null]|[string]>

The request body, if present.

## async method: Request.bodyBuffer
* since: v1.57
- returns: <[null]|[Buffer]>

The request body in a binary form. Returns null if the request has no body.

## async method: Request.bodyJSON
* since: v1.57
* langs: js, python
- returns: <[null]|[Serializable]>

Returns the request body as a parsed JSON object. If the request `Content-Type` is `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise, it parses the body as JSON.

## async method: Request.bodyJSON
* since: v1.57
* langs: csharp
- returns: <[null]|[JsonElement]>

Returns the request body as a parsed JSON object. If the request `Content-Type` is `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise, it parses the body as JSON.

## method: Request.failure
* since: v1.8
- returns: <[null]|[string]>
Expand Down Expand Up @@ -175,33 +149,35 @@ Request's method (GET, POST, etc.)

## method: Request.postData
* since: v1.8
* discouraged: Use [`method: Request.body`] instead.
- returns: <[null]|[string]>

The request body, if present.
Request's post body, if any.

## method: Request.postDataBuffer
* since: v1.8
* discouraged: Use [`method: Request.bodyBuffer`] instead.
- returns: <[null]|[Buffer]>

The request body in a binary form. Returns null if the request has no body.
Request's post body in a binary form, if any.

## method: Request.postDataJSON
* since: v1.8
* langs: js, python
* discouraged: Use [`method: Request.bodyJSON`] instead.
- returns: <[null]|[Serializable]>

Returns the request body as a parsed JSON object. If the request `Content-Type` is `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise, it parses the body as JSON.
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.

When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
Otherwise it will be parsed as JSON.

## method: Request.postDataJSON
* since: v1.12
* langs: csharp
* discouraged: Use [`method: Request.bodyJSON`] instead.
- returns: <[null]|[JsonElement]>

Returns the request body as a parsed JSON object. If the request `Content-Type` is `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise, it parses the body as JSON.
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.

When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
Otherwise it will be parsed as JSON.

## method: Request.redirectedFrom
* since: v1.8
Expand Down
32 changes: 5 additions & 27 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20378,23 +20378,6 @@ export interface Request {
*/
allHeaders(): Promise<{ [key: string]: string; }>;

/**
* The request body, if present.
*/
body(): Promise<null|string>;

/**
* The request body in a binary form. Returns null if the request has no body.
*/
bodyBuffer(): Promise<null|Buffer>;

/**
* Returns the request body as a parsed JSON object. If the request `Content-Type` is
* `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise,
* it parses the body as JSON.
*/
bodyJSON(): Promise<null|Serializable>;

/**
* The method returns `null` unless this request has failed, as reported by `requestfailed` event.
*
Expand Down Expand Up @@ -20492,25 +20475,20 @@ export interface Request {
method(): string;

/**
* **NOTE** Use [request.body()](https://playwright.dev/docs/api/class-request#request-body) instead.
*
* The request body, if present.
* Request's post body, if any.
*/
postData(): null|string;

/**
* **NOTE** Use [request.bodyBuffer()](https://playwright.dev/docs/api/class-request#request-body-buffer) instead.
*
* The request body in a binary form. Returns null if the request has no body.
* Request's post body in a binary form, if any.
*/
postDataBuffer(): null|Buffer;

/**
* **NOTE** Use [request.bodyJSON()](https://playwright.dev/docs/api/class-request#request-body-json) instead.
* Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
*
* Returns the request body as a parsed JSON object. If the request `Content-Type` is
* `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise,
* it parses the body as JSON.
* When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
* Otherwise it will be parsed as JSON.
*/
postDataJSON(): null|Serializable;

Expand Down
16 changes: 0 additions & 16 deletions packages/playwright-core/src/client/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,6 @@ export class Request extends ChannelOwner<channels.RequestChannel> implements ap
return this._fallbackOverrides.method || this._initializer.method;
}

async body(): Promise<string | null> {
return (this._fallbackOverrides.postDataBuffer || (await this._channel.body()).body)?.toString('utf-8') || null;
}

async bodyBuffer(): Promise<Buffer | null> {
return this._fallbackOverrides.postDataBuffer || (await this._channel.body()).body || null;
}

async bodyJSON(): Promise<Object | null> {
return this._postDataJSON(await this.body());
}

postData(): string | null {
return (this._fallbackOverrides.postDataBuffer || this._initializer.postData)?.toString('utf-8') || null;
}
Expand All @@ -156,10 +144,6 @@ export class Request extends ChannelOwner<channels.RequestChannel> implements ap

postDataJSON(): Object | null {
const postData = this.postData();
return this._postDataJSON(postData);
}

private _postDataJSON(postData: string | null): Object | null {
if (!postData)
return null;

Expand Down
4 changes: 0 additions & 4 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2231,10 +2231,6 @@ scheme.RequestInitializer = tObject({
hasResponse: tBoolean,
});
scheme.RequestResponseEvent = tOptional(tObject({}));
scheme.RequestBodyParams = tOptional(tObject({}));
scheme.RequestBodyResult = tObject({
body: tOptional(tBinary),
});
scheme.RequestResponseParams = tOptional(tObject({}));
scheme.RequestResponseResult = tObject({
response: tOptional(tChannel(['Response'])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ export class RequestDispatcher extends Dispatcher<Request, channels.RequestChann
this.addObjectListener(Request.Events.Response, () => this._dispatchEvent('response', {}));
}

async body(params: channels.RequestBodyParams, progress: Progress): Promise<channels.RequestBodyResult> {
const postData = this._object.postDataBuffer();
return { body: postData === null ? undefined : postData };
}

async rawRequestHeaders(params: channels.RequestRawRequestHeadersParams, progress: Progress): Promise<channels.RequestRawRequestHeadersResult> {
return { headers: await progress.race(this._object.rawRequestHeaders()) };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ export const methodMetainfo = new Map<string, { internal?: boolean, title?: stri
['ElementHandle.uncheck', { title: 'Uncheck', slowMo: true, snapshot: true, pausesBeforeInput: true, }],
['ElementHandle.waitForElementState', { title: 'Wait for state', snapshot: true, pausesBeforeAction: true, }],
['ElementHandle.waitForSelector', { title: 'Wait for selector', snapshot: true, }],
['Request.body', { title: 'Get request body', group: 'getter', }],
['Request.response', { internal: true, }],
['Request.rawRequestHeaders', { internal: true, }],
['Route.redirectNavigationRequest', { internal: true, }],
Expand Down
32 changes: 5 additions & 27 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20378,23 +20378,6 @@ export interface Request {
*/
allHeaders(): Promise<{ [key: string]: string; }>;

/**
* The request body, if present.
*/
body(): Promise<null|string>;

/**
* The request body in a binary form. Returns null if the request has no body.
*/
bodyBuffer(): Promise<null|Buffer>;

/**
* Returns the request body as a parsed JSON object. If the request `Content-Type` is
* `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise,
* it parses the body as JSON.
*/
bodyJSON(): Promise<null|Serializable>;

/**
* The method returns `null` unless this request has failed, as reported by `requestfailed` event.
*
Expand Down Expand Up @@ -20492,25 +20475,20 @@ export interface Request {
method(): string;

/**
* **NOTE** Use [request.body()](https://playwright.dev/docs/api/class-request#request-body) instead.
*
* The request body, if present.
* Request's post body, if any.
*/
postData(): null|string;

/**
* **NOTE** Use [request.bodyBuffer()](https://playwright.dev/docs/api/class-request#request-body-buffer) instead.
*
* The request body in a binary form. Returns null if the request has no body.
* Request's post body in a binary form, if any.
*/
postDataBuffer(): null|Buffer;

/**
* **NOTE** Use [request.bodyJSON()](https://playwright.dev/docs/api/class-request#request-body-json) instead.
* Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
*
* Returns the request body as a parsed JSON object. If the request `Content-Type` is
* `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise,
* it parses the body as JSON.
* When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
* Otherwise it will be parsed as JSON.
*/
postDataJSON(): null|Serializable;

Expand Down
6 changes: 0 additions & 6 deletions packages/protocol/src/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3829,16 +3829,10 @@ export interface RequestEventTarget {
}
export interface RequestChannel extends RequestEventTarget, Channel {
_type_Request: boolean;
body(params?: RequestBodyParams, progress?: Progress): Promise<RequestBodyResult>;
response(params?: RequestResponseParams, progress?: Progress): Promise<RequestResponseResult>;
rawRequestHeaders(params?: RequestRawRequestHeadersParams, progress?: Progress): Promise<RequestRawRequestHeadersResult>;
}
export type RequestResponseEvent = {};
export type RequestBodyParams = {};
export type RequestBodyOptions = {};
export type RequestBodyResult = {
body?: Binary,
};
export type RequestResponseParams = {};
export type RequestResponseOptions = {};
export type RequestResponseResult = {
Expand Down
6 changes: 0 additions & 6 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3391,12 +3391,6 @@ Request:

commands:

body:
title: Get request body
group: getter
returns:
body: binary?

response:
internal: true
returns:
Expand Down
121 changes: 0 additions & 121 deletions tests/page/network-request-body.spec.ts

This file was deleted.

Loading
Loading