File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { defaultEnvironment } from './constants'
4
4
import { generateUUID } from './utils'
5
5
import type { KyInstance } from 'ky/distribution/types/ky'
6
6
import type { BeforeRetryState } from 'ky/distribution/types/hooks'
7
- import type { Options , ResponsePromise } from 'ky'
7
+ import type { BeforeRequestHook , Options , ResponsePromise } from 'ky'
8
8
9
9
/**
10
10
* API 配置
@@ -28,6 +28,7 @@ export interface ApiConfigResolved {
28
28
idfv : string
29
29
/** `User-Agent` 请求头 */
30
30
userAgent : string
31
+ beforeRequest : BeforeRequestHook
31
32
/** 是否重试 */
32
33
beforeRetry : ( state : BeforeRetryState ) => boolean | Promise < boolean >
33
34
}
@@ -60,6 +61,7 @@ export const resolveApiConfig = (config: ApiConfig): ApiConfigResolved => {
60
61
generateUUID ( ) ||
61
62
defaultEnvironment . idfv
62
63
) . toUpperCase ( ) ,
64
+ beforeRequest : config . beforeRequest ?? ( ( ) => undefined ) ,
63
65
beforeRetry : config . beforeRetry ?? ( ( ) => false ) ,
64
66
}
65
67
}
@@ -109,6 +111,8 @@ export const resolveKyOptions = (): Options => {
109
111
)
110
112
req . headers . set ( `App-Version` , apiConfig . appVersion )
111
113
; ( req as any ) . highWaterMark = 1024 * 1024
114
+
115
+ return apiConfig . beforeRequest ( req , opt )
112
116
} ,
113
117
] ,
114
118
beforeRetry : [
You can’t perform that action at this time.
0 commit comments