From 4696f7abdacc6f79432f8c87b244e12d1fe64b7b Mon Sep 17 00:00:00 2001 From: Changhao Han Date: Thu, 25 Jun 2020 11:26:36 +0200 Subject: [PATCH] docs(new): migrate HTTPResponse docs to TSDoc (#6085) Co-authored-by: Changhao Han --- .../puppeteer.httpresponse._constructor_.md | 22 ------ .../puppeteer.httpresponse._resolvebody.md | 22 ------ new-docs/puppeteer.httpresponse.buffer.md | 2 + new-docs/puppeteer.httpresponse.frame.md | 2 + new-docs/puppeteer.httpresponse.fromcache.md | 2 + ...uppeteer.httpresponse.fromserviceworker.md | 2 + new-docs/puppeteer.httpresponse.headers.md | 2 + new-docs/puppeteer.httpresponse.json.md | 6 ++ new-docs/puppeteer.httpresponse.md | 9 ++- new-docs/puppeteer.httpresponse.ok.md | 2 + .../puppeteer.httpresponse.remoteaddress.md | 4 +- new-docs/puppeteer.httpresponse.request.md | 2 + .../puppeteer.httpresponse.securitydetails.md | 2 + new-docs/puppeteer.httpresponse.status.md | 2 + new-docs/puppeteer.httpresponse.statustext.md | 2 + new-docs/puppeteer.httpresponse.text.md | 2 + new-docs/puppeteer.httpresponse.url.md | 2 + new-docs/puppeteer.md | 3 +- new-docs/puppeteer.remoteaddress.ip.md | 11 +++ new-docs/puppeteer.remoteaddress.md | 20 ++++++ new-docs/puppeteer.remoteaddress.port.md | 11 +++ src/common/HTTPResponse.ts | 72 ++++++++++++++++++- 22 files changed, 152 insertions(+), 52 deletions(-) delete mode 100644 new-docs/puppeteer.httpresponse._constructor_.md delete mode 100644 new-docs/puppeteer.httpresponse._resolvebody.md create mode 100644 new-docs/puppeteer.remoteaddress.ip.md create mode 100644 new-docs/puppeteer.remoteaddress.md create mode 100644 new-docs/puppeteer.remoteaddress.port.md diff --git a/new-docs/puppeteer.httpresponse._constructor_.md b/new-docs/puppeteer.httpresponse._constructor_.md deleted file mode 100644 index c8ab1043d6f..00000000000 --- a/new-docs/puppeteer.httpresponse._constructor_.md +++ /dev/null @@ -1,22 +0,0 @@ - - -[Home](./index.md) > [puppeteer](./puppeteer.md) > [HTTPResponse](./puppeteer.httpresponse.md) > [(constructor)](./puppeteer.httpresponse._constructor_.md) - -## HTTPResponse.(constructor) - -Constructs a new instance of the `HTTPResponse` class - -Signature: - -```typescript -constructor(client: CDPSession, request: HTTPRequest, responsePayload: Protocol.Network.Response); -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| client | [CDPSession](./puppeteer.cdpsession.md) | | -| request | [HTTPRequest](./puppeteer.httprequest.md) | | -| responsePayload | Protocol.Network.Response | | - diff --git a/new-docs/puppeteer.httpresponse._resolvebody.md b/new-docs/puppeteer.httpresponse._resolvebody.md deleted file mode 100644 index aa1294ac795..00000000000 --- a/new-docs/puppeteer.httpresponse._resolvebody.md +++ /dev/null @@ -1,22 +0,0 @@ - - -[Home](./index.md) > [puppeteer](./puppeteer.md) > [HTTPResponse](./puppeteer.httpresponse.md) > [\_resolveBody](./puppeteer.httpresponse._resolvebody.md) - -## HTTPResponse.\_resolveBody() method - -Signature: - -```typescript -_resolveBody(err: Error | null): void; -``` - -## Parameters - -| Parameter | Type | Description | -| --- | --- | --- | -| err | Error \| null | | - -Returns: - -void - diff --git a/new-docs/puppeteer.httpresponse.buffer.md b/new-docs/puppeteer.httpresponse.buffer.md index d31a1b1c56d..1abcd0c0b8c 100644 --- a/new-docs/puppeteer.httpresponse.buffer.md +++ b/new-docs/puppeteer.httpresponse.buffer.md @@ -13,3 +13,5 @@ buffer(): Promise; Promise<Buffer> +Promise which resolves to a buffer with response body. + diff --git a/new-docs/puppeteer.httpresponse.frame.md b/new-docs/puppeteer.httpresponse.frame.md index dd1847a4202..acdba920514 100644 --- a/new-docs/puppeteer.httpresponse.frame.md +++ b/new-docs/puppeteer.httpresponse.frame.md @@ -13,3 +13,5 @@ frame(): Frame | null; [Frame](./puppeteer.frame.md) \| null +A [Frame](./puppeteer.frame.md) that initiated this response, or `null` if navigating to error pages. + diff --git a/new-docs/puppeteer.httpresponse.fromcache.md b/new-docs/puppeteer.httpresponse.fromcache.md index a89f753d7d8..b764328f491 100644 --- a/new-docs/puppeteer.httpresponse.fromcache.md +++ b/new-docs/puppeteer.httpresponse.fromcache.md @@ -13,3 +13,5 @@ fromCache(): boolean; boolean +True if the response was served from either the browser's disk cache or memory cache. + diff --git a/new-docs/puppeteer.httpresponse.fromserviceworker.md b/new-docs/puppeteer.httpresponse.fromserviceworker.md index 8df04065346..ad4c5a2e86a 100644 --- a/new-docs/puppeteer.httpresponse.fromserviceworker.md +++ b/new-docs/puppeteer.httpresponse.fromserviceworker.md @@ -13,3 +13,5 @@ fromServiceWorker(): boolean; boolean +True if the response was served by a service worker. + diff --git a/new-docs/puppeteer.httpresponse.headers.md b/new-docs/puppeteer.httpresponse.headers.md index e9193258ba8..9b53b75bdbe 100644 --- a/new-docs/puppeteer.httpresponse.headers.md +++ b/new-docs/puppeteer.httpresponse.headers.md @@ -13,3 +13,5 @@ headers(): Record; Record<string, string> +An object with HTTP headers associated with the response. All header names are lower-case. + diff --git a/new-docs/puppeteer.httpresponse.json.md b/new-docs/puppeteer.httpresponse.json.md index 141aaa462e3..c53a61b7f13 100644 --- a/new-docs/puppeteer.httpresponse.json.md +++ b/new-docs/puppeteer.httpresponse.json.md @@ -13,3 +13,9 @@ json(): Promise; Promise<any> +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`. + diff --git a/new-docs/puppeteer.httpresponse.md b/new-docs/puppeteer.httpresponse.md index 3cf9e6d4369..80e747c090b 100644 --- a/new-docs/puppeteer.httpresponse.md +++ b/new-docs/puppeteer.httpresponse.md @@ -4,23 +4,22 @@ ## HTTPResponse class +The HTTPResponse class represents responses which are received by the [Page](./puppeteer.page.md) class. + Signature: ```typescript export declare class HTTPResponse ``` -## Constructors +## Remarks -| Constructor | Modifiers | Description | -| --- | --- | --- | -| [(constructor)(client, request, responsePayload)](./puppeteer.httpresponse._constructor_.md) | | Constructs a new instance of the HTTPResponse class | +The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `HTTPResponse` class. ## Methods | Method | Modifiers | Description | | --- | --- | --- | -| [\_resolveBody(err)](./puppeteer.httpresponse._resolvebody.md) | | | | [buffer()](./puppeteer.httpresponse.buffer.md) | | | | [frame()](./puppeteer.httpresponse.frame.md) | | | | [fromCache()](./puppeteer.httpresponse.fromcache.md) | | | diff --git a/new-docs/puppeteer.httpresponse.ok.md b/new-docs/puppeteer.httpresponse.ok.md index b432851bcd6..2e696f870c0 100644 --- a/new-docs/puppeteer.httpresponse.ok.md +++ b/new-docs/puppeteer.httpresponse.ok.md @@ -13,3 +13,5 @@ ok(): boolean; boolean +True if the response was successful (status in the range 200-299). + diff --git a/new-docs/puppeteer.httpresponse.remoteaddress.md b/new-docs/puppeteer.httpresponse.remoteaddress.md index a447a82c9c8..6785c9d9cce 100644 --- a/new-docs/puppeteer.httpresponse.remoteaddress.md +++ b/new-docs/puppeteer.httpresponse.remoteaddress.md @@ -11,5 +11,7 @@ remoteAddress(): RemoteAddress; ``` Returns: -RemoteAddress +[RemoteAddress](./puppeteer.remoteaddress.md) + +The IP address and port number used to connect to the remote server. diff --git a/new-docs/puppeteer.httpresponse.request.md b/new-docs/puppeteer.httpresponse.request.md index dff022e4dab..948be3053c5 100644 --- a/new-docs/puppeteer.httpresponse.request.md +++ b/new-docs/puppeteer.httpresponse.request.md @@ -13,3 +13,5 @@ request(): HTTPRequest; [HTTPRequest](./puppeteer.httprequest.md) +A matching [HTTPRequest](./puppeteer.httprequest.md) object. + diff --git a/new-docs/puppeteer.httpresponse.securitydetails.md b/new-docs/puppeteer.httpresponse.securitydetails.md index 2d7f743262f..5ffee8df2f7 100644 --- a/new-docs/puppeteer.httpresponse.securitydetails.md +++ b/new-docs/puppeteer.httpresponse.securitydetails.md @@ -13,3 +13,5 @@ securityDetails(): SecurityDetails | null; [SecurityDetails](./puppeteer.securitydetails.md) \| null +[SecurityDetails](./puppeteer.securitydetails.md) if the response was received over the secure connection, or `null` otherwise. + diff --git a/new-docs/puppeteer.httpresponse.status.md b/new-docs/puppeteer.httpresponse.status.md index 5d922cae123..6f1b928321c 100644 --- a/new-docs/puppeteer.httpresponse.status.md +++ b/new-docs/puppeteer.httpresponse.status.md @@ -13,3 +13,5 @@ status(): number; number +The status code of the response (e.g., 200 for a success). + diff --git a/new-docs/puppeteer.httpresponse.statustext.md b/new-docs/puppeteer.httpresponse.statustext.md index 9b3840ca8e6..fd8376dccce 100644 --- a/new-docs/puppeteer.httpresponse.statustext.md +++ b/new-docs/puppeteer.httpresponse.statustext.md @@ -13,3 +13,5 @@ statusText(): string; string +The status text of the response (e.g. usually an "OK" for a success). + diff --git a/new-docs/puppeteer.httpresponse.text.md b/new-docs/puppeteer.httpresponse.text.md index d1d21ef32e8..3837c5b7792 100644 --- a/new-docs/puppeteer.httpresponse.text.md +++ b/new-docs/puppeteer.httpresponse.text.md @@ -13,3 +13,5 @@ text(): Promise; Promise<string> +Promise which resolves to a text representation of response body. + diff --git a/new-docs/puppeteer.httpresponse.url.md b/new-docs/puppeteer.httpresponse.url.md index 9101f549ff1..b81b8b4628b 100644 --- a/new-docs/puppeteer.httpresponse.url.md +++ b/new-docs/puppeteer.httpresponse.url.md @@ -13,3 +13,5 @@ url(): string; string +The URL of the response. + diff --git a/new-docs/puppeteer.md b/new-docs/puppeteer.md index e5b543386da..bf0119dd5a7 100644 --- a/new-docs/puppeteer.md +++ b/new-docs/puppeteer.md @@ -24,7 +24,7 @@ | [Frame](./puppeteer.frame.md) | | | [FrameManager](./puppeteer.framemanager.md) | | | [HTTPRequest](./puppeteer.httprequest.md) | | -| [HTTPResponse](./puppeteer.httpresponse.md) | | +| [HTTPResponse](./puppeteer.httpresponse.md) | The HTTPResponse class represents responses which are received by the [Page](./puppeteer.page.md) class. | | [JSHandle](./puppeteer.jshandle.md) | | | [Keyboard](./puppeteer.keyboard.md) | | | [Mouse](./puppeteer.mouse.md) | The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport. | @@ -55,6 +55,7 @@ | [KeyDefinition](./puppeteer.keydefinition.md) | Copyright 2017 Google Inc. All rights reserved.Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | | [Metrics](./puppeteer.metrics.md) | | | [PressOptions](./puppeteer.pressoptions.md) | | +| [RemoteAddress](./puppeteer.remoteaddress.md) | | | [SerializedAXNode](./puppeteer.serializedaxnode.md) | Represents a Node and the properties of it that are relevant to Accessibility. | | [SnapshotOptions](./puppeteer.snapshotoptions.md) | | | [WaitForTargetOptions](./puppeteer.waitfortargetoptions.md) | | diff --git a/new-docs/puppeteer.remoteaddress.ip.md b/new-docs/puppeteer.remoteaddress.ip.md new file mode 100644 index 00000000000..2dba06574f2 --- /dev/null +++ b/new-docs/puppeteer.remoteaddress.ip.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [puppeteer](./puppeteer.md) > [RemoteAddress](./puppeteer.remoteaddress.md) > [ip](./puppeteer.remoteaddress.ip.md) + +## RemoteAddress.ip property + +Signature: + +```typescript +ip: string; +``` diff --git a/new-docs/puppeteer.remoteaddress.md b/new-docs/puppeteer.remoteaddress.md new file mode 100644 index 00000000000..a9b5568c0f8 --- /dev/null +++ b/new-docs/puppeteer.remoteaddress.md @@ -0,0 +1,20 @@ + + +[Home](./index.md) > [puppeteer](./puppeteer.md) > [RemoteAddress](./puppeteer.remoteaddress.md) + +## RemoteAddress interface + + +Signature: + +```typescript +export interface RemoteAddress +``` + +## Properties + +| Property | Type | Description | +| --- | --- | --- | +| [ip](./puppeteer.remoteaddress.ip.md) | string | | +| [port](./puppeteer.remoteaddress.port.md) | number | | + diff --git a/new-docs/puppeteer.remoteaddress.port.md b/new-docs/puppeteer.remoteaddress.port.md new file mode 100644 index 00000000000..631f54697c2 --- /dev/null +++ b/new-docs/puppeteer.remoteaddress.port.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [puppeteer](./puppeteer.md) > [RemoteAddress](./puppeteer.remoteaddress.md) > [port](./puppeteer.remoteaddress.port.md) + +## RemoteAddress.port property + +Signature: + +```typescript +port: number; +``` diff --git a/src/common/HTTPResponse.ts b/src/common/HTTPResponse.ts index a8f1ad249a5..c40ecb88fea 100644 --- a/src/common/HTTPResponse.ts +++ b/src/common/HTTPResponse.ts @@ -19,11 +19,20 @@ import { HTTPRequest } from './HTTPRequest'; import { SecurityDetails } from './SecurityDetails'; import Protocol from '../protocol'; -interface RemoteAddress { +/** + * @public + */ +export interface RemoteAddress { ip: string; port: number; } +/** + * The HTTPResponse class represents responses which are received by the + * {@link Page} class. + * + * @public + */ export class HTTPResponse { private _client: CDPSession; private _request: HTTPRequest; @@ -39,6 +48,9 @@ export class HTTPResponse { private _headers: Record = {}; private _securityDetails: SecurityDetails | null; + /** + * @internal + */ constructor( client: CDPSession, request: HTTPRequest, @@ -67,38 +79,70 @@ export class HTTPResponse { : null; } + /** + * @internal + */ _resolveBody(err: Error | null): void { return this._bodyLoadedPromiseFulfill(err); } + /** + * @returns The IP address and port number used to connect to the remote + * server. + */ remoteAddress(): RemoteAddress { return this._remoteAddress; } + /** + * @returns The URL of the response. + */ url(): string { return this._url; } + /** + * @returns True if the response was successful (status in the range 200-299). + */ ok(): boolean { + // TODO: document === 0 case? return this._status === 0 || (this._status >= 200 && this._status <= 299); } + /** + * @returns The status code of the response (e.g., 200 for a success). + */ status(): number { return this._status; } + /** + * @returns The status text of the response (e.g. usually an "OK" for a + * success). + */ statusText(): string { return this._statusText; } + /** + * @returns An object with HTTP headers associated with the response. All + * header names are lower-case. + */ headers(): Record { return this._headers; } + /** + * @returns {@link SecurityDetails} if the response was received over the + * secure connection, or `null` otherwise. + */ securityDetails(): SecurityDetails | null { return this._securityDetails; } + /** + * @returns Promise which resolves to a buffer with response body. + */ buffer(): Promise { if (!this._contentPromise) { this._contentPromise = this._bodyLoadedPromise.then(async (error) => { @@ -115,28 +159,54 @@ export class HTTPResponse { return this._contentPromise; } + /** + * @returns Promise which resolves to a text representation of response body. + */ async text(): Promise { const content = await this.buffer(); return content.toString('utf8'); } + /** + * + * @returns 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`. + */ async json(): Promise { const content = await this.text(); return JSON.parse(content); } + /** + * @returns A matching {@link HTTPRequest} object. + */ request(): HTTPRequest { return this._request; } + /** + * @returns True if the response was served from either the browser's disk + * cache or memory cache. + */ fromCache(): boolean { return this._fromDiskCache || this._request._fromMemoryCache; } + /** + * @returns True if the response was served by a service worker. + */ fromServiceWorker(): boolean { return this._fromServiceWorker; } + /** + * @returns A {@link Frame} that initiated this response, or `null` if + * navigating to error pages. + */ frame(): Frame | null { return this._request.frame(); }