mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: rename Response
to HTTPResponse
(#5940)
To avoid any conflicts with the TS `Response` type.
This commit is contained in:
parent
cfd72acc57
commit
232def0dcf
60
docs/api.md
60
docs/api.md
@ -295,21 +295,21 @@
|
|||||||
* [httpRequest.respond(response)](#httprequestrespondresponse)
|
* [httpRequest.respond(response)](#httprequestrespondresponse)
|
||||||
* [httpRequest.response()](#httprequestresponse)
|
* [httpRequest.response()](#httprequestresponse)
|
||||||
* [httpRequest.url()](#httprequesturl)
|
* [httpRequest.url()](#httprequesturl)
|
||||||
- [class: Response](#class-response)
|
- [class: HTTPResponse](#class-httpresponse)
|
||||||
* [response.buffer()](#responsebuffer)
|
* [httpResponse.buffer()](#httpresponsebuffer)
|
||||||
* [response.frame()](#responseframe)
|
* [httpResponse.frame()](#httpresponseframe)
|
||||||
* [response.fromCache()](#responsefromcache)
|
* [httpResponse.fromCache()](#httpresponsefromcache)
|
||||||
* [response.fromServiceWorker()](#responsefromserviceworker)
|
* [httpResponse.fromServiceWorker()](#httpresponsefromserviceworker)
|
||||||
* [response.headers()](#responseheaders)
|
* [httpResponse.headers()](#httpresponseheaders)
|
||||||
* [response.json()](#responsejson)
|
* [httpResponse.json()](#httpresponsejson)
|
||||||
* [response.ok()](#responseok)
|
* [httpResponse.ok()](#httpresponseok)
|
||||||
* [response.remoteAddress()](#responseremoteaddress)
|
* [httpResponse.remoteAddress()](#httpresponseremoteaddress)
|
||||||
* [response.request()](#responserequest)
|
* [httpResponse.request()](#httpresponserequest)
|
||||||
* [response.securityDetails()](#responsesecuritydetails)
|
* [httpResponse.securityDetails()](#httpresponsesecuritydetails)
|
||||||
* [response.status()](#responsestatus)
|
* [httpResponse.status()](#httpresponsestatus)
|
||||||
* [response.statusText()](#responsestatustext)
|
* [httpResponse.statusText()](#httpresponsestatustext)
|
||||||
* [response.text()](#responsetext)
|
* [httpResponse.text()](#httpresponsetext)
|
||||||
* [response.url()](#responseurl)
|
* [httpResponse.url()](#httpresponseurl)
|
||||||
- [class: SecurityDetails](#class-securitydetails)
|
- [class: SecurityDetails](#class-securitydetails)
|
||||||
* [securityDetails.issuer()](#securitydetailsissuer)
|
* [securityDetails.issuer()](#securitydetailsissuer)
|
||||||
* [securityDetails.protocol()](#securitydetailsprotocol)
|
* [securityDetails.protocol()](#securitydetailsprotocol)
|
||||||
@ -3708,64 +3708,64 @@ page.on('request', request => {
|
|||||||
#### httpRequest.url()
|
#### httpRequest.url()
|
||||||
- returns: <[string]> URL of the request.
|
- returns: <[string]> URL of the request.
|
||||||
|
|
||||||
### class: Response
|
### class: HTTPResponse
|
||||||
|
|
||||||
[Response] class represents responses which are received by page.
|
[Response] class represents responses which are received by page.
|
||||||
|
|
||||||
#### response.buffer()
|
#### httpResponse.buffer()
|
||||||
- returns: <Promise<[Buffer]>> Promise which resolves to a buffer with response body.
|
- returns: <Promise<[Buffer]>> Promise which resolves to a buffer with response body.
|
||||||
|
|
||||||
#### response.frame()
|
#### httpResponse.frame()
|
||||||
- returns: <?[Frame]> A [Frame] that initiated this response, or `null` if navigating to error pages.
|
- returns: <?[Frame]> A [Frame] that initiated this response, or `null` if navigating to error pages.
|
||||||
|
|
||||||
#### response.fromCache()
|
#### httpResponse.fromCache()
|
||||||
- returns: <[boolean]>
|
- returns: <[boolean]>
|
||||||
|
|
||||||
True if the response was served from either the browser's disk cache or memory cache.
|
True if the response was served from either the browser's disk cache or memory cache.
|
||||||
|
|
||||||
#### response.fromServiceWorker()
|
#### httpResponse.fromServiceWorker()
|
||||||
- returns: <[boolean]>
|
- returns: <[boolean]>
|
||||||
|
|
||||||
True if the response was served by a service worker.
|
True if the response was served by a service worker.
|
||||||
|
|
||||||
#### response.headers()
|
#### httpResponse.headers()
|
||||||
- returns: <[Object]> An object with HTTP headers associated with the response. All header names are lower-case.
|
- returns: <[Object]> An object with HTTP headers associated with the response. All header names are lower-case.
|
||||||
|
|
||||||
#### response.json()
|
#### httpResponse.json()
|
||||||
- returns: <Promise<[Object]>> Promise which resolves to a JSON representation of response body.
|
- returns: <Promise<[Object]>> Promise which resolves to a JSON representation of response body.
|
||||||
|
|
||||||
This method will throw if the response body is not parsable via `JSON.parse`.
|
This method will throw if the response body is not parsable via `JSON.parse`.
|
||||||
|
|
||||||
#### response.ok()
|
#### httpResponse.ok()
|
||||||
- returns: <[boolean]>
|
- returns: <[boolean]>
|
||||||
|
|
||||||
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
|
Contains a boolean stating whether the response was successful (status in the range 200-299) or not.
|
||||||
|
|
||||||
#### response.remoteAddress()
|
#### httpResponse.remoteAddress()
|
||||||
- returns: <[Object]>
|
- returns: <[Object]>
|
||||||
- `ip` <[string]> the IP address of the remote server
|
- `ip` <[string]> the IP address of the remote server
|
||||||
- `port` <[number]> the port used to connect to the remote server
|
- `port` <[number]> the port used to connect to the remote server
|
||||||
|
|
||||||
#### response.request()
|
#### httpResponse.request()
|
||||||
- returns: <[Request]> A matching [Request] object.
|
- returns: <[Request]> A matching [Request] object.
|
||||||
|
|
||||||
#### response.securityDetails()
|
#### httpResponse.securityDetails()
|
||||||
- returns: <?[SecurityDetails]> Security details if the response was received over the secure connection, or `null` otherwise.
|
- returns: <?[SecurityDetails]> Security details if the response was received over the secure connection, or `null` otherwise.
|
||||||
|
|
||||||
#### response.status()
|
#### httpResponse.status()
|
||||||
- returns: <[number]>
|
- returns: <[number]>
|
||||||
|
|
||||||
Contains the status code of the response (e.g., 200 for a success).
|
Contains the status code of the response (e.g., 200 for a success).
|
||||||
|
|
||||||
#### response.statusText()
|
#### httpResponse.statusText()
|
||||||
- returns: <[string]>
|
- returns: <[string]>
|
||||||
|
|
||||||
Contains the status text of the response (e.g. usually an "OK" for a success).
|
Contains the status text of the response (e.g. usually an "OK" for a success).
|
||||||
|
|
||||||
#### response.text()
|
#### httpResponse.text()
|
||||||
- returns: <[Promise]<[string]>> Promise which resolves to a text representation of response body.
|
- returns: <[Promise]<[string]>> Promise which resolves to a text representation of response body.
|
||||||
|
|
||||||
#### response.url()
|
#### httpResponse.url()
|
||||||
- returns: <[string]>
|
- returns: <[string]>
|
||||||
|
|
||||||
Contains the URL of the response.
|
Contains the URL of the response.
|
||||||
|
@ -26,7 +26,7 @@ import { CDPSession } from './Connection';
|
|||||||
import { JSHandle, ElementHandle } from './JSHandle';
|
import { JSHandle, ElementHandle } from './JSHandle';
|
||||||
import { MouseButtonInput } from './Input';
|
import { MouseButtonInput } from './Input';
|
||||||
import { Page } from './Page';
|
import { Page } from './Page';
|
||||||
import { Response } from './Response';
|
import { HTTPResponse } from './HTTPResponse';
|
||||||
import Protocol from './protocol';
|
import Protocol from './protocol';
|
||||||
|
|
||||||
const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
|
const UTILITY_WORLD_NAME = '__puppeteer_utility_world__';
|
||||||
@ -113,7 +113,7 @@ export class FrameManager extends EventEmitter {
|
|||||||
timeout?: number;
|
timeout?: number;
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
||||||
} = {}
|
} = {}
|
||||||
): Promise<Response | null> {
|
): Promise<HTTPResponse | null> {
|
||||||
assertNoLegacyNavigationOptions(options);
|
assertNoLegacyNavigationOptions(options);
|
||||||
const {
|
const {
|
||||||
referer = this._networkManager.extraHTTPHeaders()['referer'],
|
referer = this._networkManager.extraHTTPHeaders()['referer'],
|
||||||
@ -167,7 +167,7 @@ export class FrameManager extends EventEmitter {
|
|||||||
timeout?: number;
|
timeout?: number;
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
||||||
} = {}
|
} = {}
|
||||||
): Promise<Response | null> {
|
): Promise<HTTPResponse | null> {
|
||||||
assertNoLegacyNavigationOptions(options);
|
assertNoLegacyNavigationOptions(options);
|
||||||
const {
|
const {
|
||||||
waitUntil = ['load'],
|
waitUntil = ['load'],
|
||||||
@ -412,14 +412,14 @@ export class Frame {
|
|||||||
timeout?: number;
|
timeout?: number;
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
||||||
}
|
}
|
||||||
): Promise<Response | null> {
|
): Promise<HTTPResponse | null> {
|
||||||
return await this._frameManager.navigateFrame(this, url, options);
|
return await this._frameManager.navigateFrame(this, url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForNavigation(options: {
|
async waitForNavigation(options: {
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
waitUntil?: PuppeteerLifeCycleEvent | PuppeteerLifeCycleEvent[];
|
||||||
}): Promise<Response | null> {
|
}): Promise<HTTPResponse | null> {
|
||||||
return await this._frameManager.waitForFrameNavigation(this, options);
|
return await this._frameManager.waitForFrameNavigation(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
import { CDPSession } from './Connection';
|
import { CDPSession } from './Connection';
|
||||||
import { Frame } from './FrameManager';
|
import { Frame } from './FrameManager';
|
||||||
import { Response } from './Response';
|
import { HTTPResponse } from './HTTPResponse';
|
||||||
import { helper, assert, debugError } from './helper';
|
import { helper, assert, debugError } from './helper';
|
||||||
import Protocol from './protocol';
|
import Protocol from './protocol';
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ export class HTTPRequest {
|
|||||||
_requestId: string;
|
_requestId: string;
|
||||||
_interceptionId: string;
|
_interceptionId: string;
|
||||||
_failureText = null;
|
_failureText = null;
|
||||||
_response: Response | null = null;
|
_response: HTTPResponse | null = null;
|
||||||
|
|
||||||
_fromMemoryCache = false;
|
_fromMemoryCache = false;
|
||||||
_redirectChain: HTTPRequest[];
|
_redirectChain: HTTPRequest[];
|
||||||
@ -85,7 +85,7 @@ export class HTTPRequest {
|
|||||||
return this._headers;
|
return this._headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
response(): Response | null {
|
response(): HTTPResponse | null {
|
||||||
return this._response;
|
return this._response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ interface RemoteAddress {
|
|||||||
port: number;
|
port: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Response {
|
export class HTTPResponse {
|
||||||
private _client: CDPSession;
|
private _client: CDPSession;
|
||||||
private _request: HTTPRequest;
|
private _request: HTTPRequest;
|
||||||
private _contentPromise: Promise<Buffer> | null = null;
|
private _contentPromise: Promise<Buffer> | null = null;
|
@ -19,7 +19,7 @@ import { Events } from './Events';
|
|||||||
import { TimeoutError } from './Errors';
|
import { TimeoutError } from './Errors';
|
||||||
import { FrameManager, Frame } from './FrameManager';
|
import { FrameManager, Frame } from './FrameManager';
|
||||||
import { HTTPRequest } from './HTTPRequest';
|
import { HTTPRequest } from './HTTPRequest';
|
||||||
import { Response } from './Response';
|
import { HTTPResponse } from './HTTPResponse';
|
||||||
|
|
||||||
export type PuppeteerLifeCycleEvent =
|
export type PuppeteerLifeCycleEvent =
|
||||||
| 'load'
|
| 'load'
|
||||||
@ -156,7 +156,7 @@ export class LifecycleWatcher {
|
|||||||
this._checkLifecycleComplete();
|
this._checkLifecycleComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
navigationResponse(): Response | null {
|
navigationResponse(): HTTPResponse | null {
|
||||||
return this._navigationRequest ? this._navigationRequest.response() : null;
|
return this._navigationRequest ? this._navigationRequest.response() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import { Events } from './Events';
|
|||||||
import { CDPSession } from './Connection';
|
import { CDPSession } from './Connection';
|
||||||
import { FrameManager } from './FrameManager';
|
import { FrameManager } from './FrameManager';
|
||||||
import { HTTPRequest } from './HTTPRequest';
|
import { HTTPRequest } from './HTTPRequest';
|
||||||
import { Response } from './Response';
|
import { HTTPResponse } from './HTTPResponse';
|
||||||
|
|
||||||
export interface Credentials {
|
export interface Credentials {
|
||||||
username: string;
|
username: string;
|
||||||
@ -273,7 +273,7 @@ export class NetworkManager extends EventEmitter {
|
|||||||
request: HTTPRequest,
|
request: HTTPRequest,
|
||||||
responsePayload: Protocol.Network.Response
|
responsePayload: Protocol.Network.Response
|
||||||
): void {
|
): void {
|
||||||
const response = new Response(this._client, request, responsePayload);
|
const response = new HTTPResponse(this._client, request, responsePayload);
|
||||||
request._response = response;
|
request._response = response;
|
||||||
request._redirectChain.push(request);
|
request._redirectChain.push(request);
|
||||||
response._resolveBody(
|
response._resolveBody(
|
||||||
@ -289,7 +289,7 @@ export class NetworkManager extends EventEmitter {
|
|||||||
const request = this._requestIdToRequest.get(event.requestId);
|
const request = this._requestIdToRequest.get(event.requestId);
|
||||||
// FileUpload sends a response without a matching request.
|
// FileUpload sends a response without a matching request.
|
||||||
if (!request) return;
|
if (!request) return;
|
||||||
const response = new Response(this._client, request, event.response);
|
const response = new HTTPResponse(this._client, request, event.response);
|
||||||
request._response = response;
|
request._response = response;
|
||||||
this.emit(Events.NetworkManager.Response, response);
|
this.emit(Events.NetworkManager.Response, response);
|
||||||
}
|
}
|
||||||
|
20
src/Page.ts
20
src/Page.ts
@ -33,7 +33,7 @@ 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 { HTTPRequest } from './HTTPRequest';
|
import { HTTPRequest } from './HTTPRequest';
|
||||||
import { Response as PuppeteerResponse } from './Response';
|
import { HTTPResponse } from './HTTPResponse';
|
||||||
import { Accessibility } from './Accessibility';
|
import { Accessibility } from './Accessibility';
|
||||||
import { TimeoutSettings } from './TimeoutSettings';
|
import { TimeoutSettings } from './TimeoutSettings';
|
||||||
import { FileChooser } from './FileChooser';
|
import { FileChooser } from './FileChooser';
|
||||||
@ -769,13 +769,13 @@ export class Page extends EventEmitter {
|
|||||||
async goto(
|
async goto(
|
||||||
url: string,
|
url: string,
|
||||||
options: WaitForOptions & { referer?: string }
|
options: WaitForOptions & { referer?: string }
|
||||||
): Promise<PuppeteerResponse> {
|
): Promise<HTTPResponse> {
|
||||||
return await this._frameManager.mainFrame().goto(url, options);
|
return await this._frameManager.mainFrame().goto(url, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async reload(options?: WaitForOptions): Promise<PuppeteerResponse | null> {
|
async reload(options?: WaitForOptions): Promise<HTTPResponse | null> {
|
||||||
const result = await Promise.all<
|
const result = await Promise.all<
|
||||||
PuppeteerResponse,
|
HTTPResponse,
|
||||||
Protocol.Page.reloadReturnValue
|
Protocol.Page.reloadReturnValue
|
||||||
>([this.waitForNavigation(options), this._client.send('Page.reload')]);
|
>([this.waitForNavigation(options), this._client.send('Page.reload')]);
|
||||||
|
|
||||||
@ -784,7 +784,7 @@ export class Page extends EventEmitter {
|
|||||||
|
|
||||||
async waitForNavigation(
|
async waitForNavigation(
|
||||||
options: WaitForOptions = {}
|
options: WaitForOptions = {}
|
||||||
): Promise<PuppeteerResponse | null> {
|
): Promise<HTTPResponse | null> {
|
||||||
return await this._frameManager.mainFrame().waitForNavigation(options);
|
return await this._frameManager.mainFrame().waitForNavigation(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,7 +821,7 @@ export class Page extends EventEmitter {
|
|||||||
async waitForResponse(
|
async waitForResponse(
|
||||||
urlOrPredicate: string | Function,
|
urlOrPredicate: string | Function,
|
||||||
options: { timeout?: number } = {}
|
options: { timeout?: number } = {}
|
||||||
): Promise<PuppeteerResponse> {
|
): Promise<HTTPResponse> {
|
||||||
const { timeout = this._timeoutSettings.timeout() } = options;
|
const { timeout = this._timeoutSettings.timeout() } = options;
|
||||||
return helper.waitForEvent(
|
return helper.waitForEvent(
|
||||||
this._frameManager.networkManager(),
|
this._frameManager.networkManager(),
|
||||||
@ -838,23 +838,23 @@ export class Page extends EventEmitter {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async goBack(options: WaitForOptions): Promise<PuppeteerResponse | null> {
|
async goBack(options: WaitForOptions): Promise<HTTPResponse | null> {
|
||||||
return this._go(-1, options);
|
return this._go(-1, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async goForward(options: WaitForOptions): Promise<PuppeteerResponse | null> {
|
async goForward(options: WaitForOptions): Promise<HTTPResponse | null> {
|
||||||
return this._go(+1, options);
|
return this._go(+1, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _go(
|
async _go(
|
||||||
delta: number,
|
delta: number,
|
||||||
options: WaitForOptions
|
options: WaitForOptions
|
||||||
): Promise<PuppeteerResponse | null> {
|
): Promise<HTTPResponse | null> {
|
||||||
const history = await this._client.send('Page.getNavigationHistory');
|
const history = await this._client.send('Page.getNavigationHistory');
|
||||||
const entry = history.entries[history.currentIndex + delta];
|
const entry = history.entries[history.currentIndex + delta];
|
||||||
if (!entry) return null;
|
if (!entry) return null;
|
||||||
const result = await Promise.all<
|
const result = await Promise.all<
|
||||||
PuppeteerResponse,
|
HTTPResponse,
|
||||||
Protocol.Page.navigateToHistoryEntryReturnValue
|
Protocol.Page.navigateToHistoryEntryReturnValue
|
||||||
>([
|
>([
|
||||||
this.waitForNavigation(options),
|
this.waitForNavigation(options),
|
||||||
|
@ -38,7 +38,7 @@ module.exports = {
|
|||||||
Page: require('./Page').Page,
|
Page: require('./Page').Page,
|
||||||
Puppeteer: require('./Puppeteer').Puppeteer,
|
Puppeteer: require('./Puppeteer').Puppeteer,
|
||||||
HTTPRequest: require('./HTTPRequest').HTTPRequest,
|
HTTPRequest: require('./HTTPRequest').HTTPRequest,
|
||||||
Response: require('./Response').Response,
|
HTTPResponse: require('./HTTPResponse').HTTPResponse,
|
||||||
SecurityDetails: require('./SecurityDetails').SecurityDetails,
|
SecurityDetails: require('./SecurityDetails').SecurityDetails,
|
||||||
Target: require('./Target').Target,
|
Target: require('./Target').Target,
|
||||||
TimeoutError: require('./Errors').TimeoutError,
|
TimeoutError: require('./Errors').TimeoutError,
|
||||||
|
Loading…
Reference in New Issue
Block a user