@@ -14,9 +14,13 @@ import {
14
14
EggLoggerOptions ,
15
15
EggContextLogger ,
16
16
} from 'egg-logger' ;
17
- import { RequestOptions2 as RequestOptions , HttpClientResponse } from 'urllib' ;
18
17
import {
19
- RequestURL , RequestOptions as RequestOptionsNext ,
18
+ RequestOptions2 as RequestOptionsOld ,
19
+ HttpClientResponse as HttpClientResponseOld ,
20
+ } from 'urllib' ;
21
+ import {
22
+ RequestURL ,
23
+ RequestOptions as RequestOptionsNext ,
20
24
HttpClientResponse as HttpClientResponseNext ,
21
25
} from 'urllib-next' ;
22
26
import {
@@ -49,13 +53,27 @@ declare module 'egg' {
49
53
// Remove specific property from the specific class
50
54
type RemoveSpecProp < T , P > = Pick < T , Exclude < keyof T , P > > ;
51
55
56
+ // Usage:
57
+ // ```ts
58
+ // import { HttpClientRequestURL, HttpClientRequestOptions, HttpClientResponse } from 'egg';
59
+ // async function request(url: HttpClientRequestURL, options: HttpClientRequestOptions): Promise<HttpClientResponse> {
60
+ // return await app.httpclient.request(url, options);
61
+ // }
62
+ // ```
63
+ export type HttpClientRequestURL = RequestURL ;
64
+ export type HttpClientRequestOptions = RequestOptionsNext ;
65
+ export type HttpClientResponse < T = any > = HttpClientResponseNext < T > ;
66
+
52
67
// Compatible with both urllib@2 and urllib@3 RequestOptions to request
53
68
export interface EggHttpClient extends EventEmitter {
54
- request < T = any > ( url : RequestURL ) : Promise < HttpClientResponse < T > | HttpClientResponseNext > ;
55
- request < T = any > ( url : RequestURL , options : RequestOptions | RequestOptionsNext ) : Promise < HttpClientResponse < T > | HttpClientResponseNext > ;
56
- curl < T = any > ( url : RequestURL ) : Promise < HttpClientResponse < T > | HttpClientResponseNext > ;
57
- curl < T = any > ( url : RequestURL , options : RequestOptions | RequestOptionsNext ) : Promise < HttpClientResponse < T > | HttpClientResponseNext > ;
69
+ request < T = any > ( url : HttpClientRequestURL ) : Promise < HttpClientResponseOld < T > | HttpClientResponse < T > > ;
70
+ request < T = any > ( url : HttpClientRequestURL , options : RequestOptionsOld | HttpClientRequestOptions ) :
71
+ Promise < HttpClientResponseOld < T > | HttpClientResponse < T > > ;
72
+ curl < T = any > ( url : HttpClientRequestURL ) : Promise < HttpClientResponseOld < T > | HttpClientResponse < T > > ;
73
+ curl < T = any > ( url : HttpClientRequestURL , options : RequestOptionsOld | HttpClientRequestOptions ) :
74
+ Promise < HttpClientResponseOld < T > | HttpClientResponse < T > > ;
58
75
}
76
+
59
77
interface EggHttpConstructor {
60
78
new ( app : Application ) : EggHttpClient ;
61
79
}
@@ -278,7 +296,7 @@ declare module 'egg' {
278
296
/** https.Agent */
279
297
httpsAgent ?: HttpClientBaseConfig ;
280
298
/** Default request args for httpclient */
281
- request ?: RequestOptions ;
299
+ request ?: HttpClientRequestOptions | RequestOptionsOld ;
282
300
/** Whether enable dns cache */
283
301
enableDNSCache ?: boolean ;
284
302
/** Enable proxy request, default is false. */
0 commit comments