puppeteer-core
Version:
A high-level API to control headless Chrome over the DevTools Protocol
156 lines • 4.93 kB
TypeScript
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import type Protocol from 'devtools-protocol';
import type { SecurityDetails } from '../common/SecurityDetails.js';
import type { Frame } from './Frame.js';
import type { HTTPRequest } from './HTTPRequest.js';
/**
* @public
*/
export interface RemoteAddress {
ip?: string;
port?: number;
}
/**
* The HTTPResponse class represents responses which are received by the
* {@link Page} class.
*
* @public
*/
export declare abstract class HTTPResponse {
/**
* @internal
*/
constructor();
/**
* The IP address and port number used to connect to the remote
* server.
*/
abstract remoteAddress(): RemoteAddress;
/**
* The URL of the response.
*/
abstract url(): string;
/**
* True if the response was successful (status in the range 200-299).
*/
ok(): boolean;
/**
* The status code of the response (e.g., 200 for a success).
*/
abstract status(): number;
/**
* The status text of the response (e.g. usually an "OK" for a
* success).
*/
abstract statusText(): string;
/**
* An object with HTTP headers associated with the response. All header names
* are lower-case. Duplicate header values are combined into a single
* comma-separated list except for `Set-Cookie` that is separated by `\n`.
*/
abstract headers(): Record<string, string>;
/**
* {@link SecurityDetails} if the response was received over the
* secure connection, or `null` otherwise.
*/
abstract securityDetails(): SecurityDetails | null;
/**
* Timing information related to the response.
*/
abstract timing(): Protocol.Network.ResourceTiming | null;
/**
* Total number of bytes received for this request over the network.
*
* @remarks
* The value is updated when the response finishes loading. During the
* `response` event, it only covers the bytes received up to the response
* headers. To get the total encoded transfer size (headers + compressed
* body), read it in a `requestfinished` handler or after awaiting
* {@link HTTPResponse.content}. If the request fails after the response is
* received, the value is not updated. If the browser does not report a
* size, e.g. for `data:` or `file:` URLs, the value is `0`.
*/
abstract encodedDataLength(): number;
/**
* Promise which resolves to a buffer with response body.
*
* @remarks
*
* The buffer might be re-encoded by the browser
* based on HTTP-headers or other heuristics. If the browser
* failed to detect the correct encoding, the buffer might
* be encoded incorrectly. See
* https://github.com/puppeteer/puppeteer/issues/6478.
*/
abstract content(): Promise<Uint8Array>;
/**
* Returns the response body as a stream of chunks as they arrive from the
* network.
*
* @remarks
*
* Call this from the {@link PageEvent.Response | response} event to
* receive the body while it is still loading. If the body has already
* finished loading, the stream contains the whole body as a single chunk.
*
* @experimental
*/
abstract stream(): Promise<ReadableStream<Uint8Array>>;
/**
* {@inheritDoc HTTPResponse.content}
*/
buffer(): Promise<Buffer>;
/**
* Promise which resolves to a text (utf8) representation of response body.
*
* @remarks
*
* This method will throw if the content is not utf-8 string
*/
text(): Promise<string>;
/**
* Promise which resolves to a JSON representation of response body.
*
* @remarks
*
* This method will throw if the response body is not parsable via
* `JSON.parse`.
*/
json(): Promise<any>;
/**
* Converts the response to a Fetch API Response instance.
*
* @remarks
*
* Headers are copied to the new Response instance, with multi-line
* `set-cookie` headers parsed into individual header entries.
* For responses with null body statuses (101, 204, 205, 304), the body is
* omitted.
*
* @returns A promise which resolves to a Fetch API Response object.
*/
asFetchResponse(): Promise<Response>;
/**
* A matching {@link HTTPRequest} object.
*/
abstract request(): HTTPRequest;
/**
* True if the response was served from either the browser's disk
* cache or memory cache.
*/
abstract fromCache(): boolean;
/**
* True if the response was served by a service worker.
*/
abstract fromServiceWorker(): boolean;
/**
* A {@link Frame} that initiated this response, or `null` if
* navigating to error pages.
*/
abstract frame(): Frame | null;
}
//# sourceMappingURL=HTTPResponse.d.ts.map