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