1 | /// <reference types="node" />
|
2 | import type { Buffer } from 'node:buffer';
|
3 | import type { URL } from 'node:url';
|
4 | import type { IncomingMessageWithTimings, Timings } from '@szmarczak/http-timer';
|
5 | import { RequestError } from './errors.js';
|
6 | import type { ParseJsonFunction, ResponseType } from './options.js';
|
7 | import type Request from './index.js';
|
8 | export interface PlainResponse extends IncomingMessageWithTimings {
|
9 | /**
|
10 | The original request URL.
|
11 | */
|
12 | requestUrl: URL;
|
13 | /**
|
14 | The redirect URLs.
|
15 | */
|
16 | redirectUrls: URL[];
|
17 | /**
|
18 | - `options` - The Got options that were set on this request.
|
19 |
|
20 | __Note__: This is not a [http.ClientRequest](https://nodejs.org/api/http.html#http_class_http_clientrequest).
|
21 | */
|
22 | request: Request;
|
23 | /**
|
24 | The remote IP address.
|
25 |
|
26 | This is hopefully a temporary limitation, see [lukechilds/cacheable-request#86](https://github.com/lukechilds/cacheable-request/issues/86).
|
27 |
|
28 | __Note__: Not available when the response is cached.
|
29 | */
|
30 | ip?: string;
|
31 | /**
|
32 | Whether the response was retrieved from the cache.
|
33 | */
|
34 | isFromCache: boolean;
|
35 | /**
|
36 | The status code of the response.
|
37 | */
|
38 | statusCode: number;
|
39 | /**
|
40 | The request URL or the final URL after redirects.
|
41 | */
|
42 | url: string;
|
43 | /**
|
44 | The object contains the following properties:
|
45 |
|
46 | - `start` - Time when the request started.
|
47 | - `socket` - Time when a socket was assigned to the request.
|
48 | - `lookup` - Time when the DNS lookup finished.
|
49 | - `connect` - Time when the socket successfully connected.
|
50 | - `secureConnect` - Time when the socket securely connected.
|
51 | - `upload` - Time when the request finished uploading.
|
52 | - `response` - Time when the request fired `response` event.
|
53 | - `end` - Time when the response fired `end` event.
|
54 | - `error` - Time when the request fired `error` event.
|
55 | - `abort` - Time when the request fired `abort` event.
|
56 | - `phases`
|
57 | - `wait` - `timings.socket - timings.start`
|
58 | - `dns` - `timings.lookup - timings.socket`
|
59 | - `tcp` - `timings.connect - timings.lookup`
|
60 | - `tls` - `timings.secureConnect - timings.connect`
|
61 | - `request` - `timings.upload - (timings.secureConnect || timings.connect)`
|
62 | - `firstByte` - `timings.response - timings.upload`
|
63 | - `download` - `timings.end - timings.response`
|
64 | - `total` - `(timings.end || timings.error || timings.abort) - timings.start`
|
65 |
|
66 | If something has not been measured yet, it will be `undefined`.
|
67 |
|
68 | __Note__: The time is a `number` representing the milliseconds elapsed since the UNIX epoch.
|
69 | */
|
70 | timings: Timings;
|
71 | /**
|
72 | The number of times the request was retried.
|
73 | */
|
74 | retryCount: number;
|
75 | /**
|
76 | The raw result of the request.
|
77 | */
|
78 | rawBody?: Buffer;
|
79 | /**
|
80 | The result of the request.
|
81 | */
|
82 | body?: unknown;
|
83 | }
|
84 | export interface Response<T = unknown> extends PlainResponse {
|
85 | /**
|
86 | The result of the request.
|
87 | */
|
88 | body: T;
|
89 | /**
|
90 | The raw result of the request.
|
91 | */
|
92 | rawBody: Buffer;
|
93 | }
|
94 | export declare const isResponseOk: (response: PlainResponse) => boolean;
|
95 | /**
|
96 | An error to be thrown when server response code is 2xx, and parsing body fails.
|
97 | Includes a `response` property.
|
98 | */
|
99 | export declare class ParseError extends RequestError {
|
100 | readonly response: Response;
|
101 | constructor(error: Error, response: Response);
|
102 | }
|
103 | export declare const parseBody: (response: Response, responseType: ResponseType, parseJson: ParseJsonFunction, encoding?: BufferEncoding | undefined) => unknown;
|