feat: 信令抓包

This commit is contained in:
TsMask
2023-09-23 17:20:50 +08:00
parent 08fdeb89f1
commit 6593419fb7
5 changed files with 467 additions and 105 deletions

View File

@@ -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);