1 | import { Duplex } from 'node:stream';
|
2 | import { type ClientRequest } from 'node:http';
|
3 | import type { Socket } from 'node:net';
|
4 | import { type Timings } from '@szmarczak/http-timer';
|
5 | import Options from './options.js';
|
6 | import { type PlainResponse, type Response } from './response.js';
|
7 | import { RequestError } from './errors.js';
|
8 | type Error = NodeJS.ErrnoException;
|
9 | export type Progress = {
|
10 | percent: number;
|
11 | transferred: number;
|
12 | total?: number;
|
13 | };
|
14 | export type GotEventFunction<T> =
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | ((name: 'request', listener: (request: ClientRequest) => void) => T)
|
29 |
|
30 |
|
31 |
|
32 | & (<R extends Response>(name: 'response', listener: (response: R) => void) => T)
|
33 | /**
|
34 | The `redirect` event to get the response object of a redirect. The second argument is options for the next request to the redirect location.
|
35 | */
|
36 | & (<R extends Response, N extends Options>(name: 'redirect', listener: (response: R, nextOptions: N) => void) => T)
|
37 | /**
|
38 | Progress events for uploading (sending a request) and downloading (receiving a response).
|
39 | The `progress` argument is an object like:
|
40 |
|
41 | ```
|
42 | {
|
43 | percent: 0.1,
|
44 | transferred: 1024,
|
45 | total: 10240
|
46 | }
|
47 | ```
|
48 |
|
49 | If the `content-length` header is missing, `total` will be `undefined`.
|
50 |
|
51 | @example
|
52 | ```
|
53 | import got from 'got';
|
54 |
|
55 | const response = await got('https:
|
56 | .on('downloadProgress', progress => {
|
57 |
|
58 | })
|
59 | .on('uploadProgress', progress => {
|
60 |
|
61 | });
|
62 |
|
63 | console.log(response);
|
64 | ```
|
65 | */
|
66 | & ((name: 'uploadProgress' | 'downloadProgress', listener: (progress: Progress) => void) => T)
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | & ((name: 'retry', listener: (retryCount: number, error: RequestError) => void) => T);
|
75 | export type RequestEvents<T> = {
|
76 | on: GotEventFunction<T>;
|
77 | once: GotEventFunction<T>;
|
78 | off: GotEventFunction<T>;
|
79 | };
|
80 | type UrlType = ConstructorParameters<typeof Options>[0];
|
81 | type OptionsType = ConstructorParameters<typeof Options>[1];
|
82 | type DefaultsType = ConstructorParameters<typeof Options>[2];
|
83 | export default class Request extends Duplex implements RequestEvents<Request> {
|
84 | ['constructor']: typeof Request;
|
85 | _noPipe?: boolean;
|
86 | options: Options;
|
87 | response?: PlainResponse;
|
88 | requestUrl?: URL;
|
89 | redirectUrls: URL[];
|
90 | retryCount: number;
|
91 | private _requestOptions;
|
92 | private _stopRetry;
|
93 | private _downloadedSize;
|
94 | private _uploadedSize;
|
95 | private _stopReading;
|
96 | private readonly _pipedServerResponses;
|
97 | private _request?;
|
98 | private _responseSize?;
|
99 | private _bodySize?;
|
100 | private _unproxyEvents;
|
101 | private _isFromCache?;
|
102 | private _cannotHaveBody;
|
103 | private _triggerRead;
|
104 | private readonly _jobs;
|
105 | private _cancelTimeouts;
|
106 | private readonly _removeListeners;
|
107 | private _nativeResponse?;
|
108 | private _flushed;
|
109 | private _aborted;
|
110 | private _requestInitialized;
|
111 | constructor(url: UrlType, options?: OptionsType, defaults?: DefaultsType);
|
112 | flush(): Promise<void>;
|
113 | _beforeError(error: Error): void;
|
114 | _read(): void;
|
115 | _write(chunk: unknown, encoding: BufferEncoding | undefined, callback: (error?: Error | null) => void): void;
|
116 | _final(callback: (error?: Error | null) => void): void;
|
117 | _destroy(error: Error | null, callback: (error: Error | null) => void): void;
|
118 | pipe<T extends NodeJS.WritableStream>(destination: T, options?: {
|
119 | end?: boolean;
|
120 | }): T;
|
121 | unpipe<T extends NodeJS.WritableStream>(destination: T): this;
|
122 | private _finalizeBody;
|
123 | private _onResponseBase;
|
124 | private _setRawBody;
|
125 | private _onResponse;
|
126 | private _onRequest;
|
127 | private _asyncWrite;
|
128 | private _sendBody;
|
129 | private _prepareCache;
|
130 | private _createCacheableRequest;
|
131 | private _makeRequest;
|
132 | private _error;
|
133 | private _writeRequest;
|
134 | |
135 |
|
136 |
|
137 | get ip(): string | undefined;
|
138 | |
139 |
|
140 |
|
141 | get isAborted(): boolean;
|
142 | get socket(): Socket | undefined;
|
143 | |
144 |
|
145 |
|
146 | get downloadProgress(): Progress;
|
147 | |
148 |
|
149 |
|
150 | get uploadProgress(): Progress;
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | get timings(): Timings | undefined;
|
179 | |
180 |
|
181 |
|
182 | get isFromCache(): boolean | undefined;
|
183 | get reusedSocket(): boolean | undefined;
|
184 | }
|
185 | export {};
|
186 |
|
\ | No newline at end of file |