docs(new): migrate HTTPResponse docs to TSDoc (#6085)

Co-authored-by: Changhao Han <changhaohan@chromium.org>
This commit is contained in:
Changhao Han 2020-06-25 11:26:36 +02:00 committed by Mathias Bynens
parent b993adb468
commit 4696f7abda
22 changed files with 152 additions and 52 deletions

View File

@ -1,22 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [HTTPResponse](./puppeteer.httpresponse.md) &gt; [(constructor)](./puppeteer.httpresponse._constructor_.md)
## HTTPResponse.(constructor)
Constructs a new instance of the `HTTPResponse` class
<b>Signature:</b>
```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 | |

View File

@ -1,22 +0,0 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [HTTPResponse](./puppeteer.httpresponse.md) &gt; [\_resolveBody](./puppeteer.httpresponse._resolvebody.md)
## HTTPResponse.\_resolveBody() method
<b>Signature:</b>
```typescript
_resolveBody(err: Error | null): void;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| err | Error \| null | |
<b>Returns:</b>
void

View File

@ -13,3 +13,5 @@ buffer(): Promise<Buffer>;
Promise&lt;Buffer&gt;
Promise which resolves to a buffer with response body.

View File

@ -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.

View File

@ -13,3 +13,5 @@ fromCache(): boolean;
boolean
True if the response was served from either the browser's disk cache or memory cache.

View File

@ -13,3 +13,5 @@ fromServiceWorker(): boolean;
boolean
True if the response was served by a service worker.

View File

@ -13,3 +13,5 @@ headers(): Record<string, string>;
Record&lt;string, string&gt;
An object with HTTP headers associated with the response. All header names are lower-case.

View File

@ -13,3 +13,9 @@ json(): Promise<any>;
Promise&lt;any&gt;
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`<!-- -->.

View File

@ -4,23 +4,22 @@
## HTTPResponse class
The HTTPResponse class represents responses which are received by the [Page](./puppeteer.page.md) class.
<b>Signature:</b>
```typescript
export declare class HTTPResponse
```
## Constructors
## Remarks
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [(constructor)(client, request, responsePayload)](./puppeteer.httpresponse._constructor_.md) | | Constructs a new instance of the <code>HTTPResponse</code> 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) | | |

View File

@ -13,3 +13,5 @@ ok(): boolean;
boolean
True if the response was successful (status in the range 200-299).

View File

@ -11,5 +11,7 @@ remoteAddress(): RemoteAddress;
```
<b>Returns:</b>
RemoteAddress
[RemoteAddress](./puppeteer.remoteaddress.md)
The IP address and port number used to connect to the remote server.

View File

@ -13,3 +13,5 @@ request(): HTTPRequest;
[HTTPRequest](./puppeteer.httprequest.md)
A matching [HTTPRequest](./puppeteer.httprequest.md) object.

View File

@ -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.

View File

@ -13,3 +13,5 @@ status(): number;
number
The status code of the response (e.g., 200 for a success).

View File

@ -13,3 +13,5 @@ statusText(): string;
string
The status text of the response (e.g. usually an "OK" for a success).

View File

@ -13,3 +13,5 @@ text(): Promise<string>;
Promise&lt;string&gt;
Promise which resolves to a text representation of response body.

View File

@ -13,3 +13,5 @@ url(): string;
string
The URL of the response.

View File

@ -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 at<!-- -->http://www.apache.org/licenses/LICENSE-2.0<!-- -->Unless 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) | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [RemoteAddress](./puppeteer.remoteaddress.md) &gt; [ip](./puppeteer.remoteaddress.ip.md)
## RemoteAddress.ip property
<b>Signature:</b>
```typescript
ip: string;
```

View File

@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [RemoteAddress](./puppeteer.remoteaddress.md)
## RemoteAddress interface
<b>Signature:</b>
```typescript
export interface RemoteAddress
```
## Properties
| Property | Type | Description |
| --- | --- | --- |
| [ip](./puppeteer.remoteaddress.ip.md) | string | |
| [port](./puppeteer.remoteaddress.port.md) | number | |

View File

@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [RemoteAddress](./puppeteer.remoteaddress.md) &gt; [port](./puppeteer.remoteaddress.port.md)
## RemoteAddress.port property
<b>Signature:</b>
```typescript
port: number;
```

View File

@ -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<string, string> = {};
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<string, string> {
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<Buffer> {
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<string> {
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<any> {
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();
}