Skip to content

Commit

Permalink
api: make request.postData() return null instead of undefined (#1366)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman committed Mar 12, 2020
1 parent be83cba commit 3fa4255
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/api.md
Expand Up @@ -3365,7 +3365,7 @@ Whether this request is driving frame's navigation.
- returns: <[string]> Request's method (GET, POST, etc.)

#### request.postData()
- returns: <[string]> Request's post body, if any.
- returns: <?[string]> Request's post body, if any.

#### request.redirectChain()
- returns: <[Array]<[Request]>>
Expand Down
2 changes: 1 addition & 1 deletion src/chromium/crNetworkManager.ts
Expand Up @@ -255,7 +255,7 @@ class InterceptableRequest implements network.RequestDelegate {
this._documentId = documentId;

this.request = new network.Request(allowInterception ? this : null, frame, redirectChain, documentId,
event.request.url, (event.type || '').toLowerCase(), event.request.method, event.request.postData, headersObject(event.request.headers));
event.request.url, (event.type || '').toLowerCase(), event.request.method, event.request.postData || null, headersObject(event.request.headers));
}

async continue(overrides: { method?: string; headers?: network.Headers; postData?: string } = {}) {
Expand Down
2 changes: 1 addition & 1 deletion src/firefox/ffNetworkManager.ts
Expand Up @@ -155,7 +155,7 @@ class InterceptableRequest implements network.RequestDelegate {
headers[name.toLowerCase()] = value;

this.request = new network.Request(payload.isIntercepted ? this : null, frame, redirectChain, payload.navigationId,
payload.url, causeToResourceType[payload.cause] || 'other', payload.method, payload.postData, headers);
payload.url, causeToResourceType[payload.cause] || 'other', payload.method, payload.postData || null, headers);
}

async continue(overrides: { method?: string; headers?: network.Headers; postData?: string }) {
Expand Down
6 changes: 3 additions & 3 deletions src/network.ts
Expand Up @@ -105,7 +105,7 @@ export class Request {
private _url: string;
private _resourceType: string;
private _method: string;
private _postData: string | undefined;
private _postData: string | null;
private _headers: Headers;
private _frame: frames.Frame;
private _waitForResponsePromise: Promise<Response>;
Expand All @@ -115,7 +115,7 @@ export class Request {
private _interceptionHandled = false;

constructor(delegate: RequestDelegate | null, frame: frames.Frame, redirectChain: Request[], documentId: string | undefined,
url: string, resourceType: string, method: string, postData: string | undefined, headers: Headers) {
url: string, resourceType: string, method: string, postData: string | null, headers: Headers) {
assert(!url.startsWith('data:'), 'Data urls should not fire requests');
this._delegate = delegate;
this._frame = frame;
Expand Down Expand Up @@ -151,7 +151,7 @@ export class Request {
return this._method;
}

postData(): string | undefined {
postData(): string | null {
return this._postData;
}

Expand Down
2 changes: 1 addition & 1 deletion src/webkit/wkInterceptableRequest.ts
Expand Up @@ -50,7 +50,7 @@ export class WKInterceptableRequest implements network.RequestDelegate {
this._session = session;
this._requestId = event.requestId;
this.request = new network.Request(allowInterception ? this : null, frame, redirectChain, documentId, event.request.url,
event.type ? event.type.toLowerCase() : 'Unknown', event.request.method, event.request.postData, headersObject(event.request.headers));
event.type ? event.type.toLowerCase() : 'Unknown', event.request.method, event.request.postData || null, headersObject(event.request.headers));
this._interceptedPromise = new Promise(f => this._interceptedCallback = f);
}

Expand Down
2 changes: 1 addition & 1 deletion test/browsercontext.spec.js
Expand Up @@ -376,7 +376,7 @@ module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FF
expect(request.url()).toContain('empty.html');
expect(request.headers()['user-agent']).toBeTruthy();
expect(request.method()).toBe('GET');
expect(request.postData()).toBe(undefined);
expect(request.postData()).toBe(null);
expect(request.isNavigationRequest()).toBe(true);
expect(request.resourceType()).toBe('document');
expect(request.frame() === page.mainFrame()).toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions test/interception.spec.js
Expand Up @@ -36,7 +36,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
expect(request.url()).toContain('empty.html');
expect(request.headers()['user-agent']).toBeTruthy();
expect(request.method()).toBe('GET');
expect(request.postData()).toBe(undefined);
expect(request.postData()).toBe(null);
expect(request.isNavigationRequest()).toBe(true);
expect(request.resourceType()).toBe('document');
expect(request.frame() === page.mainFrame()).toBe(true);
Expand Down Expand Up @@ -586,7 +586,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p
expect(request.url()).toContain('empty.html');
expect(request.headers()['user-agent']).toBeTruthy();
expect(request.method()).toBe('GET');
expect(request.postData()).toBe(undefined);
expect(request.postData()).toBe(null);
expect(request.isNavigationRequest()).toBe(true);
expect(request.resourceType()).toBe('document');
expect(request.frame() === page.mainFrame()).toBe(true);
Expand Down
2 changes: 1 addition & 1 deletion test/network.spec.js
Expand Up @@ -112,7 +112,7 @@ module.exports.describe = function({testRunner, expect, MAC, WIN, FFOX, CHROMIUM
});
it('should be |undefined| when there is no post data', async({page, server}) => {
const response = await page.goto(server.EMPTY_PAGE);
expect(response.request().postData()).toBe(undefined);
expect(response.request().postData()).toBe(null);
});
});

Expand Down

0 comments on commit 3fa4255

Please sign in to comment.