2023-03-15 16:51:34 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2023 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Protocol from 'devtools-protocol';
|
|
|
|
|
|
|
|
import {Frame} from '../common/Frame.js';
|
|
|
|
import {SecurityDetails} from '../common/SecurityDetails.js';
|
|
|
|
|
|
|
|
import {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 class HTTPResponse {
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
_resolveBody(_err: Error | null): void {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* The IP address and port number used to connect to the remote
|
2023-03-15 16:51:34 +00:00
|
|
|
* server.
|
|
|
|
*/
|
|
|
|
remoteAddress(): RemoteAddress {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* The URL of the response.
|
2023-03-15 16:51:34 +00:00
|
|
|
*/
|
|
|
|
url(): string {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* True if the response was successful (status in the range 200-299).
|
2023-03-15 16:51:34 +00:00
|
|
|
*/
|
|
|
|
ok(): boolean {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* The status code of the response (e.g., 200 for a success).
|
2023-03-15 16:51:34 +00:00
|
|
|
*/
|
|
|
|
status(): number {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* The status text of the response (e.g. usually an "OK" for a
|
2023-03-15 16:51:34 +00:00
|
|
|
* success).
|
|
|
|
*/
|
|
|
|
statusText(): string {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* An object with HTTP headers associated with the response. All
|
2023-03-15 16:51:34 +00:00
|
|
|
* header names are lower-case.
|
|
|
|
*/
|
|
|
|
headers(): Record<string, string> {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* {@link SecurityDetails} if the response was received over the
|
2023-03-15 16:51:34 +00:00
|
|
|
* secure connection, or `null` otherwise.
|
|
|
|
*/
|
|
|
|
securityDetails(): SecurityDetails | null {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* Timing information related to the response.
|
2023-03-15 16:51:34 +00:00
|
|
|
*/
|
|
|
|
timing(): Protocol.Network.ResourceTiming | null {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* Promise which resolves to a buffer with response body.
|
2023-03-15 16:51:34 +00:00
|
|
|
*/
|
|
|
|
buffer(): Promise<Buffer> {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* Promise which resolves to a text representation of response body.
|
2023-03-15 16:51:34 +00:00
|
|
|
*/
|
|
|
|
async text(): Promise<string> {
|
|
|
|
const content = await this.buffer();
|
|
|
|
return content.toString('utf8');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* Promise which resolves to a JSON representation of response body.
|
2023-03-15 16:51:34 +00:00
|
|
|
*
|
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* A matching {@link HTTPRequest} object.
|
2023-03-15 16:51:34 +00:00
|
|
|
*/
|
|
|
|
request(): HTTPRequest {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* True if the response was served from either the browser's disk
|
2023-03-15 16:51:34 +00:00
|
|
|
* cache or memory cache.
|
|
|
|
*/
|
|
|
|
fromCache(): boolean {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* True if the response was served by a service worker.
|
2023-03-15 16:51:34 +00:00
|
|
|
*/
|
|
|
|
fromServiceWorker(): boolean {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-03-30 11:54:00 +00:00
|
|
|
* A {@link Frame} that initiated this response, or `null` if
|
2023-03-15 16:51:34 +00:00
|
|
|
* navigating to error pages.
|
|
|
|
*/
|
|
|
|
frame(): Frame | null {
|
|
|
|
throw new Error('Not implemented');
|
|
|
|
}
|
|
|
|
}
|