feat: 信令抓包
This commit is contained in:
@@ -69,6 +69,8 @@ type OptionsType = {
|
||||
repeatSubmit?: boolean;
|
||||
/**携带授权Token请求头 */
|
||||
whithToken?: boolean;
|
||||
/**中断控制信号,timeout不会生效 */
|
||||
signal?: AbortSignal;
|
||||
};
|
||||
|
||||
/**默认请求参数 */
|
||||
@@ -87,6 +89,7 @@ const FATCH_OPTIONS: OptionsType = {
|
||||
credentials: undefined,
|
||||
repeatSubmit: true,
|
||||
whithToken: true,
|
||||
signal: undefined
|
||||
};
|
||||
|
||||
/**请求前的拦截 */
|
||||
@@ -200,15 +203,17 @@ function interceptorResponse(res: ResultType): ResultType | Promise<any> {
|
||||
* @returns 返回 Promise<ResultType>
|
||||
*/
|
||||
export async function request(options: OptionsType): Promise<ResultType> {
|
||||
options = Object.assign({}, FATCH_OPTIONS, options);
|
||||
let timeoutId: any = 0;
|
||||
// 请求超时控制请求终止
|
||||
const controller = new AbortController();
|
||||
const { signal } = controller;
|
||||
|
||||
options = Object.assign({ signal }, FATCH_OPTIONS, options);
|
||||
|
||||
const timeoutId = setTimeout(() => {
|
||||
controller.abort(); // 终止请求
|
||||
}, options.timeout);
|
||||
if (!options.signal) {
|
||||
const controller = new AbortController();
|
||||
const { signal } = controller;
|
||||
options.signal = signal;
|
||||
timeoutId = setTimeout(() => {
|
||||
controller.abort(); // 终止请求
|
||||
}, options.timeout);
|
||||
}
|
||||
|
||||
// 检查请求拦截
|
||||
const beforeReq = beforeRequest(options);
|
||||
|
||||
Reference in New Issue
Block a user