Skip to content

Commit 46d5ea0

Browse files
authored
Revert "feat: add request.body async getters (#38179)" (#38281)
1 parent 0778fcf commit 46d5ea0

File tree

11 files changed

+21
-248
lines changed

11 files changed

+21
-248
lines changed

docs/src/api/class-request.md

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,6 @@ request is issued to a redirected url.
2323

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

26-
## async method: Request.body
27-
* since: v1.57
28-
- returns: <[null]|[string]>
29-
30-
The request body, if present.
31-
32-
## async method: Request.bodyBuffer
33-
* since: v1.57
34-
- returns: <[null]|[Buffer]>
35-
36-
The request body in a binary form. Returns null if the request has no body.
37-
38-
## async method: Request.bodyJSON
39-
* since: v1.57
40-
* langs: js, python
41-
- returns: <[null]|[Serializable]>
42-
43-
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.
44-
45-
## async method: Request.bodyJSON
46-
* since: v1.57
47-
* langs: csharp
48-
- returns: <[null]|[JsonElement]>
49-
50-
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.
51-
5226
## method: Request.failure
5327
* since: v1.8
5428
- returns: <[null]|[string]>
@@ -175,33 +149,35 @@ Request's method (GET, POST, etc.)
175149

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

181-
The request body, if present.
154+
Request's post body, if any.
182155

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

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

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

196-
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.
167+
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
168+
169+
When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
170+
Otherwise it will be parsed as JSON.
197171

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

204-
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.
177+
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
178+
179+
When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
180+
Otherwise it will be parsed as JSON.
205181

206182
## method: Request.redirectedFrom
207183
* since: v1.8

packages/playwright-client/types/types.d.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20378,23 +20378,6 @@ export interface Request {
2037820378
*/
2037920379
allHeaders(): Promise<{ [key: string]: string; }>;
2038020380

20381-
/**
20382-
* The request body, if present.
20383-
*/
20384-
body(): Promise<null|string>;
20385-
20386-
/**
20387-
* The request body in a binary form. Returns null if the request has no body.
20388-
*/
20389-
bodyBuffer(): Promise<null|Buffer>;
20390-
20391-
/**
20392-
* Returns the request body as a parsed JSON object. If the request `Content-Type` is
20393-
* `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise,
20394-
* it parses the body as JSON.
20395-
*/
20396-
bodyJSON(): Promise<null|Serializable>;
20397-
2039820381
/**
2039920382
* The method returns `null` unless this request has failed, as reported by `requestfailed` event.
2040020383
*
@@ -20492,25 +20475,20 @@ export interface Request {
2049220475
method(): string;
2049320476

2049420477
/**
20495-
* **NOTE** Use [request.body()](https://playwright.dev/docs/api/class-request#request-body) instead.
20496-
*
20497-
* The request body, if present.
20478+
* Request's post body, if any.
2049820479
*/
2049920480
postData(): null|string;
2050020481

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

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

packages/playwright-core/src/client/network.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,6 @@ export class Request extends ChannelOwner<channels.RequestChannel> implements ap
134134
return this._fallbackOverrides.method || this._initializer.method;
135135
}
136136

137-
async body(): Promise<string | null> {
138-
return (this._fallbackOverrides.postDataBuffer || (await this._channel.body()).body)?.toString('utf-8') || null;
139-
}
140-
141-
async bodyBuffer(): Promise<Buffer | null> {
142-
return this._fallbackOverrides.postDataBuffer || (await this._channel.body()).body || null;
143-
}
144-
145-
async bodyJSON(): Promise<Object | null> {
146-
return this._postDataJSON(await this.body());
147-
}
148-
149137
postData(): string | null {
150138
return (this._fallbackOverrides.postDataBuffer || this._initializer.postData)?.toString('utf-8') || null;
151139
}
@@ -156,10 +144,6 @@ export class Request extends ChannelOwner<channels.RequestChannel> implements ap
156144

157145
postDataJSON(): Object | null {
158146
const postData = this.postData();
159-
return this._postDataJSON(postData);
160-
}
161-
162-
private _postDataJSON(postData: string | null): Object | null {
163147
if (!postData)
164148
return null;
165149

packages/playwright-core/src/protocol/validator.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,10 +2231,6 @@ scheme.RequestInitializer = tObject({
22312231
hasResponse: tBoolean,
22322232
});
22332233
scheme.RequestResponseEvent = tOptional(tObject({}));
2234-
scheme.RequestBodyParams = tOptional(tObject({}));
2235-
scheme.RequestBodyResult = tObject({
2236-
body: tOptional(tBinary),
2237-
});
22382234
scheme.RequestResponseParams = tOptional(tObject({}));
22392235
scheme.RequestResponseResult = tObject({
22402236
response: tOptional(tChannel(['Response'])),

packages/playwright-core/src/server/dispatchers/networkDispatchers.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ export class RequestDispatcher extends Dispatcher<Request, channels.RequestChann
6666
this.addObjectListener(Request.Events.Response, () => this._dispatchEvent('response', {}));
6767
}
6868

69-
async body(params: channels.RequestBodyParams, progress: Progress): Promise<channels.RequestBodyResult> {
70-
const postData = this._object.postDataBuffer();
71-
return { body: postData === null ? undefined : postData };
72-
}
73-
7469
async rawRequestHeaders(params: channels.RequestRawRequestHeadersParams, progress: Progress): Promise<channels.RequestRawRequestHeadersResult> {
7570
return { headers: await progress.race(this._object.rawRequestHeaders()) };
7671
}

packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ export const methodMetainfo = new Map<string, { internal?: boolean, title?: stri
236236
['ElementHandle.uncheck', { title: 'Uncheck', slowMo: true, snapshot: true, pausesBeforeInput: true, }],
237237
['ElementHandle.waitForElementState', { title: 'Wait for state', snapshot: true, pausesBeforeAction: true, }],
238238
['ElementHandle.waitForSelector', { title: 'Wait for selector', snapshot: true, }],
239-
['Request.body', { title: 'Get request body', group: 'getter', }],
240239
['Request.response', { internal: true, }],
241240
['Request.rawRequestHeaders', { internal: true, }],
242241
['Route.redirectNavigationRequest', { internal: true, }],

packages/playwright-core/types/types.d.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20378,23 +20378,6 @@ export interface Request {
2037820378
*/
2037920379
allHeaders(): Promise<{ [key: string]: string; }>;
2038020380

20381-
/**
20382-
* The request body, if present.
20383-
*/
20384-
body(): Promise<null|string>;
20385-
20386-
/**
20387-
* The request body in a binary form. Returns null if the request has no body.
20388-
*/
20389-
bodyBuffer(): Promise<null|Buffer>;
20390-
20391-
/**
20392-
* Returns the request body as a parsed JSON object. If the request `Content-Type` is
20393-
* `application/x-www-form-urlencoded`, this method returns a key/value object parsed from the form data. Otherwise,
20394-
* it parses the body as JSON.
20395-
*/
20396-
bodyJSON(): Promise<null|Serializable>;
20397-
2039820381
/**
2039920382
* The method returns `null` unless this request has failed, as reported by `requestfailed` event.
2040020383
*
@@ -20492,25 +20475,20 @@ export interface Request {
2049220475
method(): string;
2049320476

2049420477
/**
20495-
* **NOTE** Use [request.body()](https://playwright.dev/docs/api/class-request#request-body) instead.
20496-
*
20497-
* The request body, if present.
20478+
* Request's post body, if any.
2049820479
*/
2049920480
postData(): null|string;
2050020481

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

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

packages/protocol/src/channels.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3829,16 +3829,10 @@ export interface RequestEventTarget {
38293829
}
38303830
export interface RequestChannel extends RequestEventTarget, Channel {
38313831
_type_Request: boolean;
3832-
body(params?: RequestBodyParams, progress?: Progress): Promise<RequestBodyResult>;
38333832
response(params?: RequestResponseParams, progress?: Progress): Promise<RequestResponseResult>;
38343833
rawRequestHeaders(params?: RequestRawRequestHeadersParams, progress?: Progress): Promise<RequestRawRequestHeadersResult>;
38353834
}
38363835
export type RequestResponseEvent = {};
3837-
export type RequestBodyParams = {};
3838-
export type RequestBodyOptions = {};
3839-
export type RequestBodyResult = {
3840-
body?: Binary,
3841-
};
38423836
export type RequestResponseParams = {};
38433837
export type RequestResponseOptions = {};
38443838
export type RequestResponseResult = {

packages/protocol/src/protocol.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,12 +3391,6 @@ Request:
33913391

33923392
commands:
33933393

3394-
body:
3395-
title: Get request body
3396-
group: getter
3397-
returns:
3398-
body: binary?
3399-
34003394
response:
34013395
internal: true
34023396
returns:

tests/page/network-request-body.spec.ts

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)