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