chore: rename Request class to HTTPRequest (#5934)

It conflicts with an inbuilt TypeScript `Request` type so can cause
confusion when in TS land. Note: `Response.ts` and `Worker.ts` also
suffer from this; PRs to rename them are incoming.
This commit is contained in:
Jack Franklin 2020-05-29 09:38:40 +01:00 committed by GitHub
parent 9737059400
commit 8e8a9df3dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 47 additions and 47 deletions

View File

@ -281,20 +281,20 @@
* [elementHandle.toString()](#elementhandletostring) * [elementHandle.toString()](#elementhandletostring)
* [elementHandle.type(text[, options])](#elementhandletypetext-options) * [elementHandle.type(text[, options])](#elementhandletypetext-options)
* [elementHandle.uploadFile(...filePaths)](#elementhandleuploadfilefilepaths) * [elementHandle.uploadFile(...filePaths)](#elementhandleuploadfilefilepaths)
- [class: Request](#class-request) - [class: HTTPRequest](#class-httprequest)
* [request.abort([errorCode])](#requestaborterrorcode) * [httpRequest.abort([errorCode])](#httprequestaborterrorcode)
* [request.continue([overrides])](#requestcontinueoverrides) * [httpRequest.continue([overrides])](#httprequestcontinueoverrides)
* [request.failure()](#requestfailure) * [httpRequest.failure()](#httprequestfailure)
* [request.frame()](#requestframe) * [httpRequest.frame()](#httprequestframe)
* [request.headers()](#requestheaders) * [httpRequest.headers()](#httprequestheaders)
* [request.isNavigationRequest()](#requestisnavigationrequest) * [httpRequest.isNavigationRequest()](#httprequestisnavigationrequest)
* [request.method()](#requestmethod) * [httpRequest.method()](#httprequestmethod)
* [request.postData()](#requestpostdata) * [httpRequest.postData()](#httprequestpostdata)
* [request.redirectChain()](#requestredirectchain) * [httpRequest.redirectChain()](#httprequestredirectchain)
* [request.resourceType()](#requestresourcetype) * [httpRequest.resourceType()](#httprequestresourcetype)
* [request.respond(response)](#requestrespondresponse) * [httpRequest.respond(response)](#httprequestrespondresponse)
* [request.response()](#requestresponse) * [httpRequest.response()](#httprequestresponse)
* [request.url()](#requesturl) * [httpRequest.url()](#httprequesturl)
- [class: Response](#class-response) - [class: Response](#class-response)
* [response.buffer()](#responsebuffer) * [response.buffer()](#responsebuffer)
* [response.frame()](#responseframe) * [response.frame()](#responseframe)
@ -3543,7 +3543,7 @@ await elementHandle.press('Enter');
This method expects `elementHandle` to point to an [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). This method expects `elementHandle` to point to an [input element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input).
### class: Request ### class: HTTPRequest
Whenever the page sends a request, such as for a network resource, the following events are emitted by puppeteer's page: Whenever the page sends a request, such as for a network resource, the following events are emitted by puppeteer's page:
- [`'request'`](#event-request) emitted when the request is issued by the page. - [`'request'`](#event-request) emitted when the request is issued by the page.
@ -3556,7 +3556,7 @@ If request fails at some point, then instead of `'requestfinished'` event (and p
If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a redirected url. If request gets a 'redirect' response, the request is successfully finished with the 'requestfinished' event, and a new request is issued to a redirected url.
#### request.abort([errorCode]) #### httpRequest.abort([errorCode])
- `errorCode` <[string]> Optional error code. Defaults to `failed`, could be - `errorCode` <[string]> Optional error code. Defaults to `failed`, could be
one of the following: one of the following:
- `aborted` - An operation was aborted (due to user action) - `aborted` - An operation was aborted (due to user action)
@ -3579,7 +3579,7 @@ If request gets a 'redirect' response, the request is successfully finished with
Aborts request. To use this, request interception should be enabled with `page.setRequestInterception`. Aborts request. To use this, request interception should be enabled with `page.setRequestInterception`.
Exception is immediately thrown if the request interception is not enabled. Exception is immediately thrown if the request interception is not enabled.
#### request.continue([overrides]) #### httpRequest.continue([overrides])
- `overrides` <[Object]> Optional request overwrites, which can be one of the following: - `overrides` <[Object]> Optional request overwrites, which can be one of the following:
- `url` <[string]> If set, the request url will be changed. This is not a redirect. The request will be silently forwarded to the new url. For example, the address bar will show the original url. - `url` <[string]> If set, the request url will be changed. This is not a redirect. The request will be silently forwarded to the new url. For example, the address bar will show the original url.
- `method` <[string]> If set changes the request method (e.g. `GET` or `POST`) - `method` <[string]> If set changes the request method (e.g. `GET` or `POST`)
@ -3602,7 +3602,7 @@ page.on('request', request => {
}); });
``` ```
#### request.failure() #### httpRequest.failure()
- returns: <?[Object]> Object describing request failure, if any - returns: <?[Object]> Object describing request failure, if any
- `errorText` <[string]> Human-readable error message, e.g. `'net::ERR_FAILED'`. - `errorText` <[string]> Human-readable error message, e.g. `'net::ERR_FAILED'`.
@ -3617,24 +3617,24 @@ page.on('requestfailed', request => {
}); });
``` ```
#### request.frame() #### httpRequest.frame()
- returns: <?[Frame]> A [Frame] that initiated this request, or `null` if navigating to error pages. - returns: <?[Frame]> A [Frame] that initiated this request, or `null` if navigating to error pages.
#### request.headers() #### httpRequest.headers()
- returns: <[Object]> An object with HTTP headers associated with the request. All header names are lower-case. - returns: <[Object]> An object with HTTP headers associated with the request. All header names are lower-case.
#### request.isNavigationRequest() #### httpRequest.isNavigationRequest()
- returns: <[boolean]> - returns: <[boolean]>
Whether this request is driving frame's navigation. Whether this request is driving frame's navigation.
#### request.method() #### httpRequest.method()
- returns: <[string]> Request's method (GET, POST, etc.) - returns: <[string]> Request's method (GET, POST, etc.)
#### request.postData() #### httpRequest.postData()
- returns: <[string]> Request's post body, if any. - returns: <[string]> Request's post body, if any.
#### request.redirectChain() #### httpRequest.redirectChain()
- returns: <[Array]<[Request]>> - returns: <[Array]<[Request]>>
A `redirectChain` is a chain of requests initiated to fetch a resource. A `redirectChain` is a chain of requests initiated to fetch a resource.
@ -3661,13 +3661,13 @@ const chain = response.request().redirectChain();
console.log(chain.length); // 0 console.log(chain.length); // 0
``` ```
#### request.resourceType() #### httpRequest.resourceType()
- returns: <[string]> - returns: <[string]>
Contains the request's resource type as it was perceived by the rendering engine. Contains the request's resource type as it was perceived by the rendering engine.
ResourceType will be one of the following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`, `websocket`, `manifest`, `other`. ResourceType will be one of the following: `document`, `stylesheet`, `image`, `media`, `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`, `websocket`, `manifest`, `other`.
#### request.respond(response) #### httpRequest.respond(response)
- `response` <[Object]> Response that will fulfill this request - `response` <[Object]> Response that will fulfill this request
- `status` <[number]> Response status code, defaults to `200`. - `status` <[number]> Response status code, defaults to `200`.
- `headers` <[Object]> Optional response headers. Header values will be converted to a string. - `headers` <[Object]> Optional response headers. Header values will be converted to a string.
@ -3695,10 +3695,10 @@ page.on('request', request => {
> **NOTE** Mocking responses for dataURL requests is not supported. > **NOTE** Mocking responses for dataURL requests is not supported.
> Calling `request.respond` for a dataURL request is a noop. > Calling `request.respond` for a dataURL request is a noop.
#### request.response() #### httpRequest.response()
- returns: <?[Response]> A matching [Response] object, or `null` if the response has not been received yet. - returns: <?[Response]> A matching [Response] object, or `null` if the response has not been received yet.
#### request.url() #### httpRequest.url()
- returns: <[string]> URL of the request. - returns: <[string]> URL of the request.
### class: Response ### class: Response

View File

@ -19,14 +19,14 @@ import { Response } from './Response';
import { helper, assert, debugError } from './helper'; import { helper, assert, debugError } from './helper';
import Protocol from './protocol'; import Protocol from './protocol';
export class Request { export class HTTPRequest {
_requestId: string; _requestId: string;
_interceptionId: string; _interceptionId: string;
_failureText = null; _failureText = null;
_response: Response | null = null; _response: Response | null = null;
_fromMemoryCache = false; _fromMemoryCache = false;
_redirectChain: Request[]; _redirectChain: HTTPRequest[];
private _client: CDPSession; private _client: CDPSession;
private _isNavigationRequest: boolean; private _isNavigationRequest: boolean;
@ -46,7 +46,7 @@ export class Request {
interceptionId: string, interceptionId: string,
allowInterception: boolean, allowInterception: boolean,
event: Protocol.Network.requestWillBeSentPayload, event: Protocol.Network.requestWillBeSentPayload,
redirectChain: Request[] redirectChain: HTTPRequest[]
) { ) {
this._client = client; this._client = client;
this._requestId = event.requestId; this._requestId = event.requestId;
@ -97,7 +97,7 @@ export class Request {
return this._isNavigationRequest; return this._isNavigationRequest;
} }
redirectChain(): Request[] { redirectChain(): HTTPRequest[] {
return this._redirectChain.slice(); return this._redirectChain.slice();
} }

View File

@ -18,7 +18,7 @@ import { helper, assert, PuppeteerEventListener } from './helper';
import { Events } from './Events'; import { Events } from './Events';
import { TimeoutError } from './Errors'; import { TimeoutError } from './Errors';
import { FrameManager, Frame } from './FrameManager'; import { FrameManager, Frame } from './FrameManager';
import { Request } from './Request'; import { HTTPRequest } from './HTTPRequest';
import { Response } from './Response'; import { Response } from './Response';
export type PuppeteerLifeCycleEvent = export type PuppeteerLifeCycleEvent =
@ -47,7 +47,7 @@ export class LifecycleWatcher {
_frameManager: FrameManager; _frameManager: FrameManager;
_frame: Frame; _frame: Frame;
_timeout: number; _timeout: number;
_navigationRequest?: Request; _navigationRequest?: HTTPRequest;
_eventListeners: PuppeteerEventListener[]; _eventListeners: PuppeteerEventListener[];
_initialLoaderId: string; _initialLoaderId: string;
@ -139,7 +139,7 @@ export class LifecycleWatcher {
this._checkLifecycleComplete(); this._checkLifecycleComplete();
} }
_onRequest(request: Request): void { _onRequest(request: HTTPRequest): void {
if (request.frame() !== this._frame || !request.isNavigationRequest()) if (request.frame() !== this._frame || !request.isNavigationRequest())
return; return;
this._navigationRequest = request; this._navigationRequest = request;

View File

@ -19,7 +19,7 @@ import Protocol from './protocol';
import { Events } from './Events'; import { Events } from './Events';
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { FrameManager } from './FrameManager'; import { FrameManager } from './FrameManager';
import { Request } from './Request'; import { HTTPRequest } from './HTTPRequest';
import { Response } from './Response'; import { Response } from './Response';
export interface Credentials { export interface Credentials {
@ -31,7 +31,7 @@ export class NetworkManager extends EventEmitter {
_client: CDPSession; _client: CDPSession;
_ignoreHTTPSErrors: boolean; _ignoreHTTPSErrors: boolean;
_frameManager: FrameManager; _frameManager: FrameManager;
_requestIdToRequest = new Map<string, Request>(); _requestIdToRequest = new Map<string, HTTPRequest>();
_requestIdToRequestWillBeSentEvent = new Map< _requestIdToRequestWillBeSentEvent = new Map<
string, string,
Protocol.Network.requestWillBeSentPayload Protocol.Network.requestWillBeSentPayload
@ -250,7 +250,7 @@ export class NetworkManager extends EventEmitter {
const frame = event.frameId const frame = event.frameId
? this._frameManager.frame(event.frameId) ? this._frameManager.frame(event.frameId)
: null; : null;
const request = new Request( const request = new HTTPRequest(
this._client, this._client,
frame, frame,
interceptionId, interceptionId,
@ -270,7 +270,7 @@ export class NetworkManager extends EventEmitter {
} }
_handleRequestRedirect( _handleRequestRedirect(
request: Request, request: HTTPRequest,
responsePayload: Protocol.Network.Response responsePayload: Protocol.Network.Response
): void { ): void {
const response = new Response(this._client, request, responsePayload); const response = new Response(this._client, request, responsePayload);

View File

@ -32,7 +32,7 @@ import { Target } from './Target';
import { createJSHandle, JSHandle, ElementHandle } from './JSHandle'; import { createJSHandle, JSHandle, ElementHandle } from './JSHandle';
import type { Viewport } from './PuppeteerViewport'; import type { Viewport } from './PuppeteerViewport';
import { Credentials } from './NetworkManager'; import { Credentials } from './NetworkManager';
import { Request as PuppeteerRequest } from './Request'; import { HTTPRequest } from './HTTPRequest';
import { Response as PuppeteerResponse } from './Response'; import { Response as PuppeteerResponse } from './Response';
import { Accessibility } from './Accessibility'; import { Accessibility } from './Accessibility';
import { TimeoutSettings } from './TimeoutSettings'; import { TimeoutSettings } from './TimeoutSettings';
@ -801,7 +801,7 @@ export class Page extends EventEmitter {
async waitForRequest( async waitForRequest(
urlOrPredicate: string | Function, urlOrPredicate: string | Function,
options: { timeout?: number } = {} options: { timeout?: number } = {}
): Promise<PuppeteerRequest> { ): Promise<HTTPRequest> {
const { timeout = this._timeoutSettings.timeout() } = options; const { timeout = this._timeoutSettings.timeout() } = options;
return helper.waitForEvent( return helper.waitForEvent(
this._frameManager.networkManager(), this._frameManager.networkManager(),

View File

@ -15,7 +15,7 @@
*/ */
import { CDPSession } from './Connection'; import { CDPSession } from './Connection';
import { Frame } from './FrameManager'; import { Frame } from './FrameManager';
import { Request } from './Request'; import { HTTPRequest } from './HTTPRequest';
import { SecurityDetails } from './SecurityDetails'; import { SecurityDetails } from './SecurityDetails';
import Protocol from './protocol'; import Protocol from './protocol';
@ -26,7 +26,7 @@ interface RemoteAddress {
export class Response { export class Response {
private _client: CDPSession; private _client: CDPSession;
private _request: Request; private _request: HTTPRequest;
private _contentPromise: Promise<Buffer> | null = null; private _contentPromise: Promise<Buffer> | null = null;
private _bodyLoadedPromise: Promise<Error | void>; private _bodyLoadedPromise: Promise<Error | void>;
private _bodyLoadedPromiseFulfill: (err: Error | void) => void; private _bodyLoadedPromiseFulfill: (err: Error | void) => void;
@ -41,7 +41,7 @@ export class Response {
constructor( constructor(
client: CDPSession, client: CDPSession,
request: Request, request: HTTPRequest,
responsePayload: Protocol.Network.Response responsePayload: Protocol.Network.Response
) { ) {
this._client = client; this._client = client;
@ -125,7 +125,7 @@ export class Response {
return JSON.parse(content); return JSON.parse(content);
} }
request(): Request { request(): HTTPRequest {
return this._request; return this._request;
} }

View File

@ -36,7 +36,7 @@ module.exports = {
Mouse: require('./Input').Mouse, Mouse: require('./Input').Mouse,
Page: require('./Page').Page, Page: require('./Page').Page,
Puppeteer: require('./Puppeteer').Puppeteer, Puppeteer: require('./Puppeteer').Puppeteer,
Request: require('./Request').Request, HTTPRequest: require('./HTTPRequest').HTTPRequest,
Response: require('./Response').Response, Response: require('./Response').Response,
SecurityDetails: require('./SecurityDetails').SecurityDetails, SecurityDetails: require('./SecurityDetails').SecurityDetails,
Target: require('./Target').Target, Target: require('./Target').Target,

View File

@ -377,7 +377,7 @@ function compareDocumentations(actual, expected) {
}, },
], ],
[ [
'Method Request.abort() errorCode', 'Method HTTPRequest.abort() errorCode',
{ {
actualName: 'string', actualName: 'string',
expectedName: 'ErrorCode', expectedName: 'ErrorCode',