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