mphttpx 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/global.js +1 -0
- package/dist/index.cjs.js +2349 -0
- package/dist/index.cjs.min.js +1 -0
- package/dist/index.d.ts +823 -0
- package/dist/index.esm.js +2312 -0
- package/dist/index.esm.min.js +1 -0
- package/dist/types/AbortControllerP.d.ts +20 -0
- package/dist/types/AbortSignalP.d.ts +37 -0
- package/dist/types/BlobP.d.ts +30 -0
- package/dist/types/BodyP.d.ts +33 -0
- package/dist/types/CustomEventP.d.ts +21 -0
- package/dist/types/EventP.d.ts +64 -0
- package/dist/types/EventTargetP.d.ts +37 -0
- package/dist/types/FileP.d.ts +23 -0
- package/dist/types/FileReaderP.d.ts +67 -0
- package/dist/types/FormDataP.d.ts +37 -0
- package/dist/types/HeadersP.d.ts +31 -0
- package/dist/types/ProgressEventP.d.ts +24 -0
- package/dist/types/RequestP.d.ts +45 -0
- package/dist/types/ResponseP.d.ts +39 -0
- package/dist/types/TextDecoderP.d.ts +31 -0
- package/dist/types/TextEncoderP.d.ts +15 -0
- package/dist/types/URLSearchParamsP.d.ts +31 -0
- package/dist/types/XMLHttpRequestEventTargetP.d.ts +47 -0
- package/dist/types/XMLHttpRequestP.d.ts +94 -0
- package/dist/types/XMLHttpRequestUploadP.d.ts +10 -0
- package/dist/types/fetchP.d.ts +3 -0
- package/dist/types/global.d.ts +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/isPolyfill.d.ts +9 -0
- package/dist/types/platform.d.ts +4 -0
- package/dist/types/request.d.ts +362 -0
- package/package.json +30 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare const state: unique symbol;
|
|
2
|
+
export declare class TextDecoderP implements TextDecoder {
|
|
3
|
+
constructor(utfLabel?: string, { fatal, ignoreBOM }?: {
|
|
4
|
+
fatal?: boolean | undefined;
|
|
5
|
+
ignoreBOM?: boolean | undefined;
|
|
6
|
+
});
|
|
7
|
+
[state]: TextDecoderState;
|
|
8
|
+
get encoding(): string;
|
|
9
|
+
get fatal(): boolean;
|
|
10
|
+
get ignoreBOM(): boolean;
|
|
11
|
+
decode(buffer?: TAllowSharedBufferSource, { stream }?: {
|
|
12
|
+
stream?: boolean | undefined;
|
|
13
|
+
}): string;
|
|
14
|
+
toString(): string;
|
|
15
|
+
get isPolyfill(): {
|
|
16
|
+
symbol: symbol;
|
|
17
|
+
hierarchy: string[];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
declare class TextDecoderState {
|
|
21
|
+
fatal: boolean;
|
|
22
|
+
ignoreBOM: boolean;
|
|
23
|
+
_bomSeen: boolean;
|
|
24
|
+
_partial: number[];
|
|
25
|
+
}
|
|
26
|
+
type TAllowSharedBufferSource = NonNullable<Parameters<TextDecoder["decode"]>[0]>;
|
|
27
|
+
declare const TextDecoderE: {
|
|
28
|
+
new (label?: string, options?: TextDecoderOptions): TextDecoder;
|
|
29
|
+
prototype: TextDecoder;
|
|
30
|
+
};
|
|
31
|
+
export { TextDecoderE as TextDecoder };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class TextEncoderP implements TextEncoder {
|
|
2
|
+
get encoding(): string;
|
|
3
|
+
encode(input?: string): Uint8Array<ArrayBuffer>;
|
|
4
|
+
encodeInto(source: string, destination: Uint8Array): TextEncoderEncodeIntoResult;
|
|
5
|
+
toString(): string;
|
|
6
|
+
get isPolyfill(): {
|
|
7
|
+
symbol: symbol;
|
|
8
|
+
hierarchy: string[];
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
declare const TextEncoderE: {
|
|
12
|
+
new (): TextEncoder;
|
|
13
|
+
prototype: TextEncoder;
|
|
14
|
+
};
|
|
15
|
+
export { TextEncoderE as TextEncoder };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { state } from "./isPolyfill";
|
|
2
|
+
export declare class URLSearchParamsP implements URLSearchParams {
|
|
3
|
+
constructor(init?: string[][] | Record<string, string> | string | URLSearchParams);
|
|
4
|
+
[state]: URLSearchParamsState;
|
|
5
|
+
get size(): number;
|
|
6
|
+
append(name: string, value: string): void;
|
|
7
|
+
delete(name: string, value?: string): void;
|
|
8
|
+
get(name: string): string | null;
|
|
9
|
+
getAll(name: string): string[];
|
|
10
|
+
has(name: string, value?: string): boolean;
|
|
11
|
+
set(name: string, value: string): void;
|
|
12
|
+
sort(): void;
|
|
13
|
+
forEach(callbackfn: (value: string, key: string, parent: URLSearchParams) => void, thisArg?: any): void;
|
|
14
|
+
entries(): ArrayIterator<[string, string]>;
|
|
15
|
+
keys(): ArrayIterator<string>;
|
|
16
|
+
values(): ArrayIterator<string>;
|
|
17
|
+
[Symbol.iterator](): ArrayIterator<[string, string]>;
|
|
18
|
+
toString(): string;
|
|
19
|
+
get isPolyfill(): {
|
|
20
|
+
symbol: symbol;
|
|
21
|
+
hierarchy: string[];
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
declare class URLSearchParamsState {
|
|
25
|
+
_dict: Record<string, string[]>;
|
|
26
|
+
}
|
|
27
|
+
declare const URLSearchParamsE: {
|
|
28
|
+
new (init?: string[][] | Record<string, string> | string | URLSearchParams): URLSearchParams;
|
|
29
|
+
prototype: URLSearchParams;
|
|
30
|
+
};
|
|
31
|
+
export { URLSearchParamsE as URLSearchParams };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { state } from "./isPolyfill";
|
|
2
|
+
import { EventTargetP } from "./EventTargetP";
|
|
3
|
+
export declare class XMLHttpRequestEventTargetP extends EventTargetP implements XMLHttpRequestEventTarget {
|
|
4
|
+
constructor();
|
|
5
|
+
[state]: XMLHttpRequestEventTargetState;
|
|
6
|
+
get onabort(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
7
|
+
set onabort(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null);
|
|
8
|
+
get onerror(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
9
|
+
set onerror(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null);
|
|
10
|
+
get onload(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
11
|
+
set onload(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null);
|
|
12
|
+
get onloadend(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
13
|
+
set onloadend(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null);
|
|
14
|
+
get onloadstart(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
15
|
+
set onloadstart(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null);
|
|
16
|
+
get onprogress(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
17
|
+
set onprogress(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null);
|
|
18
|
+
get ontimeout(): ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
19
|
+
set ontimeout(value: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null);
|
|
20
|
+
toString(): string;
|
|
21
|
+
get isPolyfill(): {
|
|
22
|
+
symbol: symbol;
|
|
23
|
+
hierarchy: string[];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare class XMLHttpRequestEventTargetState {
|
|
27
|
+
/**
|
|
28
|
+
* @param _target XMLHttpRequestEventTargetP
|
|
29
|
+
*/
|
|
30
|
+
constructor(_target: unknown);
|
|
31
|
+
target: XMLHttpRequest;
|
|
32
|
+
attach(type: keyof XMLHttpRequestEventTargetEventMap): void;
|
|
33
|
+
onabort: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
34
|
+
_onabort: (ev: ProgressEvent) => void;
|
|
35
|
+
onerror: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
36
|
+
_onerror: (ev: ProgressEvent) => void;
|
|
37
|
+
onload: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
38
|
+
_onload: (ev: ProgressEvent) => void;
|
|
39
|
+
onloadend: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
40
|
+
_onloadend: (ev: ProgressEvent) => void;
|
|
41
|
+
onloadstart: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
42
|
+
_onloadstart: (ev: ProgressEvent) => void;
|
|
43
|
+
onprogress: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
44
|
+
_onprogress: (ev: ProgressEvent) => void;
|
|
45
|
+
ontimeout: ((this: XMLHttpRequest, ev: ProgressEvent) => any) | null;
|
|
46
|
+
_ontimeout: (ev: ProgressEvent) => void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { XMLHttpRequestEventTargetP } from "./XMLHttpRequestEventTargetP";
|
|
2
|
+
import { XMLHttpRequestUploadP } from "./XMLHttpRequestUploadP";
|
|
3
|
+
import type { IRequestTask, IRequestSuccessCallbackBaseResult, IRequestFailCallbackResult, IAliRequestFailCallbackResult } from "./request";
|
|
4
|
+
declare const state: unique symbol;
|
|
5
|
+
export { state as xhrState };
|
|
6
|
+
export declare class XMLHttpRequestP extends XMLHttpRequestEventTargetP implements XMLHttpRequest {
|
|
7
|
+
static readonly UNSENT = 0;
|
|
8
|
+
static readonly OPENED = 1;
|
|
9
|
+
static readonly HEADERS_RECEIVED = 2;
|
|
10
|
+
static readonly LOADING = 3;
|
|
11
|
+
static readonly DONE = 4;
|
|
12
|
+
constructor();
|
|
13
|
+
[state]: XMLHttpRequestState;
|
|
14
|
+
readonly UNSENT = 0;
|
|
15
|
+
readonly OPENED = 1;
|
|
16
|
+
readonly HEADERS_RECEIVED = 2;
|
|
17
|
+
readonly LOADING = 3;
|
|
18
|
+
readonly DONE = 4;
|
|
19
|
+
get readyState(): number;
|
|
20
|
+
get response(): any;
|
|
21
|
+
get responseText(): string;
|
|
22
|
+
get responseType(): XMLHttpRequestResponseType;
|
|
23
|
+
set responseType(value: XMLHttpRequestResponseType);
|
|
24
|
+
get responseURL(): string;
|
|
25
|
+
get responseXML(): Document | null;
|
|
26
|
+
get status(): number;
|
|
27
|
+
get statusText(): string;
|
|
28
|
+
get timeout(): number;
|
|
29
|
+
set timeout(value: number);
|
|
30
|
+
get upload(): XMLHttpRequestUploadP;
|
|
31
|
+
get withCredentials(): boolean;
|
|
32
|
+
set withCredentials(value: boolean);
|
|
33
|
+
abort(): void;
|
|
34
|
+
getAllResponseHeaders(): string;
|
|
35
|
+
getResponseHeader(name: string): string | null;
|
|
36
|
+
open(...args: [method: string, url: string | URL, async?: boolean, username?: string | null, password?: string | null]): void;
|
|
37
|
+
overrideMimeType(mime: string): void;
|
|
38
|
+
send(body?: Document | XMLHttpRequestBodyInit | null): void;
|
|
39
|
+
setRequestHeader(name: string, value: string): void;
|
|
40
|
+
get onreadystatechange(): ((this: XMLHttpRequest, ev: Event) => any) | null;
|
|
41
|
+
set onreadystatechange(value: ((this: XMLHttpRequest, ev: Event) => any) | null);
|
|
42
|
+
toString(): string;
|
|
43
|
+
get isPolyfill(): {
|
|
44
|
+
symbol: symbol;
|
|
45
|
+
hierarchy: string[];
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
declare class XMLHttpRequestState {
|
|
49
|
+
constructor(target: XMLHttpRequestP);
|
|
50
|
+
target: XMLHttpRequestP;
|
|
51
|
+
readyState: number;
|
|
52
|
+
response: any;
|
|
53
|
+
responseType: XMLHttpRequestResponseType;
|
|
54
|
+
responseURL: string;
|
|
55
|
+
status: number;
|
|
56
|
+
statusText: string;
|
|
57
|
+
timeout: number;
|
|
58
|
+
upload: XMLHttpRequestUploadP;
|
|
59
|
+
withCredentials: boolean;
|
|
60
|
+
_reqCanSend: boolean;
|
|
61
|
+
_resetPending: boolean;
|
|
62
|
+
_timeoutId: number;
|
|
63
|
+
_reqURL: string;
|
|
64
|
+
_method: string;
|
|
65
|
+
_reqHeaders: Record<string, string>;
|
|
66
|
+
_resHeaders: Record<string, string> | null;
|
|
67
|
+
_resContLen: number;
|
|
68
|
+
_requestTask: IRequestTask | null;
|
|
69
|
+
execRequest(body?: Document | XMLHttpRequestBodyInit | null): void;
|
|
70
|
+
requestSuccess({ statusCode, header, data }: IRequestSuccessCallbackBaseResult): void;
|
|
71
|
+
requestFail(err: IRequestFailCallbackResult | IAliRequestFailCallbackResult): void;
|
|
72
|
+
requestComplete(): void;
|
|
73
|
+
clearRequest(delay?: boolean): void;
|
|
74
|
+
checkRequestTimeout(): void;
|
|
75
|
+
resetXHR(): void;
|
|
76
|
+
resetRequestTimeout(): void;
|
|
77
|
+
emitProcessEvent(type: string, loaded?: number, total?: number, target?: XMLHttpRequestEventTargetP): void;
|
|
78
|
+
setReadyStateAndNotify(value: number): void;
|
|
79
|
+
onreadystatechange: ((this: XMLHttpRequest, ev: Event) => any) | null;
|
|
80
|
+
_onreadystatechange: (ev: Event) => void;
|
|
81
|
+
}
|
|
82
|
+
export declare function normalizeMethod(method: string): string;
|
|
83
|
+
export declare function convert(body?: Parameters<XMLHttpRequest["send"]>[0], setContentType?: (str: string) => void, setContentLength?: (num: number) => void): string | ArrayBuffer;
|
|
84
|
+
export declare function convertBack(type: XMLHttpRequestResponseType, data?: IRequestSuccessCallbackBaseResult["data"]): string | object | ArrayBuffer | Blob;
|
|
85
|
+
declare const XMLHttpRequestE: {
|
|
86
|
+
new (): XMLHttpRequest;
|
|
87
|
+
prototype: XMLHttpRequest;
|
|
88
|
+
readonly UNSENT: 0;
|
|
89
|
+
readonly OPENED: 1;
|
|
90
|
+
readonly HEADERS_RECEIVED: 2;
|
|
91
|
+
readonly LOADING: 3;
|
|
92
|
+
readonly DONE: 4;
|
|
93
|
+
} | typeof XMLHttpRequestP;
|
|
94
|
+
export { XMLHttpRequestE as XMLHttpRequest };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { XMLHttpRequestEventTargetP } from "./XMLHttpRequestEventTargetP";
|
|
2
|
+
export declare class XMLHttpRequestUploadP extends XMLHttpRequestEventTargetP implements XMLHttpRequestUpload {
|
|
3
|
+
constructor();
|
|
4
|
+
toString(): string;
|
|
5
|
+
get isPolyfill(): {
|
|
6
|
+
symbol: symbol;
|
|
7
|
+
hierarchy: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export declare function createXMLHttpRequestUploadP(): XMLHttpRequestUploadP;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { TextEncoder, TextEncoderP } from "./TextEncoderP";
|
|
2
|
+
export { TextDecoder, TextDecoderP } from "./TextDecoderP";
|
|
3
|
+
export { Event, EventP } from "./EventP";
|
|
4
|
+
export { EventTarget, EventTargetP } from "./EventTargetP";
|
|
5
|
+
export { CustomEvent, CustomEventP } from "./CustomEventP";
|
|
6
|
+
export { ProgressEvent, ProgressEventP } from "./ProgressEventP";
|
|
7
|
+
export { Blob, BlobP } from "./BlobP";
|
|
8
|
+
export { File, FileP } from "./FileP";
|
|
9
|
+
export { FileReader, FileReaderP } from "./FileReaderP";
|
|
10
|
+
export { FormData, FormDataP } from "./FormDataP";
|
|
11
|
+
export { URLSearchParams, URLSearchParamsP } from "./URLSearchParamsP";
|
|
12
|
+
export { AbortSignal, AbortSignalP } from "./AbortSignalP";
|
|
13
|
+
export { AbortController, AbortControllerP } from "./AbortControllerP";
|
|
14
|
+
export { XMLHttpRequest, XMLHttpRequestP } from "./XMLHttpRequestP";
|
|
15
|
+
export { fetch, fetchP } from "./fetchP";
|
|
16
|
+
export { Headers, HeadersP } from "./HeadersP";
|
|
17
|
+
export { Request, RequestP } from "./RequestP";
|
|
18
|
+
export { Response, ResponseP } from "./ResponseP";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const polyfill: unique symbol;
|
|
2
|
+
export declare const state: unique symbol;
|
|
3
|
+
export declare const g: typeof globalThis;
|
|
4
|
+
export declare function isObjectType<T>(name: string, value: unknown): value is T;
|
|
5
|
+
export declare function isPolyfillType<T>(name: string, value: unknown): value is T;
|
|
6
|
+
export declare class MPException extends Error {
|
|
7
|
+
constructor(message?: string, name?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare function defineStringTag(targetFunc: Function, stringTag: string): void;
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
export declare const request: TRequestFunc;
|
|
2
|
+
/**
|
|
3
|
+
* 发起 HTTPS 网络请求。
|
|
4
|
+
*/
|
|
5
|
+
export type TRequestFunc = (options: IRequestOptions) => IRequestTask;
|
|
6
|
+
export interface IRequestOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 开发者服务器接口地址
|
|
9
|
+
*/
|
|
10
|
+
url: string;
|
|
11
|
+
/**
|
|
12
|
+
* 请求的参数
|
|
13
|
+
*/
|
|
14
|
+
data?: string | object | ArrayBuffer;
|
|
15
|
+
/**
|
|
16
|
+
* 设置请求的 header,header 中不能设置 Referer。content-type 默认为 application/json
|
|
17
|
+
*/
|
|
18
|
+
header?: object;
|
|
19
|
+
/**
|
|
20
|
+
* 超时时间,单位为毫秒。默认值为 60000
|
|
21
|
+
*/
|
|
22
|
+
timeout?: number;
|
|
23
|
+
/**
|
|
24
|
+
* HTTP 请求方法
|
|
25
|
+
* 默认值:GET
|
|
26
|
+
*/
|
|
27
|
+
method?: "OPTIONS" | "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "TRACE" | "CONNECT";
|
|
28
|
+
/**
|
|
29
|
+
* 返回的数据格式
|
|
30
|
+
* 合法值:
|
|
31
|
+
* - json(默认值): 返回的数据为 JSON,返回后会对返回的数据进行一次 JSON.parse
|
|
32
|
+
* - 其他: 不对返回的内容进行 JSON.parse
|
|
33
|
+
*/
|
|
34
|
+
dataType?: "json" | "text";
|
|
35
|
+
/**
|
|
36
|
+
* 响应的数据类型
|
|
37
|
+
* 合法值:
|
|
38
|
+
* - text(默认值): 响应的数据为文本
|
|
39
|
+
* - arraybuffer: 响应的数据为 ArrayBuffer
|
|
40
|
+
*/
|
|
41
|
+
responseType?: "text" | "arraybuffer";
|
|
42
|
+
/**
|
|
43
|
+
* 使用高性能模式。从基础库 v3.5.0 开始在 Android 端默认开启,其他端暂不生效。该模式下有更优的网络性能表现,更多信息请查看下方说明。
|
|
44
|
+
* 默认值:true
|
|
45
|
+
*/
|
|
46
|
+
useHighPerformanceMode?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* 开启 http2
|
|
49
|
+
* 默认值:false
|
|
50
|
+
*/
|
|
51
|
+
enableHttp2?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* 是否开启 profile。iOS 和 Android 端默认开启,其他端暂不支持。开启后可在接口回调的 res.profile 中查看性能调试信息。
|
|
54
|
+
* 默认值:true
|
|
55
|
+
*/
|
|
56
|
+
enableProfile?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 是否开启 Quic/h3 协议(iOS 微信目前使用 gQUIC-Q43;Android 微信在 v8.0.54 前使用 gQUIC-Q43,v8.0.54 开始使用 IETF QUIC,即 h3 协议;PC微信使用 IETF QUIC,即 h3 协议)
|
|
59
|
+
* 默认值:false
|
|
60
|
+
*/
|
|
61
|
+
enableQuic?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* 开启 Http 缓存
|
|
64
|
+
* 默认值:false
|
|
65
|
+
*/
|
|
66
|
+
enableCache?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 是否开启 HttpDNS 服务。如开启,需要同时填入 httpDNSServiceId 。
|
|
69
|
+
* 默认值:false
|
|
70
|
+
*/
|
|
71
|
+
enableHttpDNS?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* HttpDNS 服务商 Id。
|
|
74
|
+
*/
|
|
75
|
+
httpDNSServiceId?: string;
|
|
76
|
+
/**
|
|
77
|
+
* HttpDNS 超时时间。HttpDNS解析时间超过该值时不再走HttpDNS,本次请求将回退到localDNS。默认为 60000 毫秒。
|
|
78
|
+
* 默认值:60000
|
|
79
|
+
*/
|
|
80
|
+
httpDNSTimeout?: number;
|
|
81
|
+
/**
|
|
82
|
+
* 开启 transfer-encoding chunked。
|
|
83
|
+
* 默认值:false
|
|
84
|
+
*/
|
|
85
|
+
enableChunked?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* 强制使用蜂窝网络发送请求
|
|
88
|
+
* 默认值:false
|
|
89
|
+
*/
|
|
90
|
+
forceCellularNetwork?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* 重定向拦截策略。(目前安卓、iOS、开发者工具已支持,PC端将在后续支持)
|
|
93
|
+
* 合法值:
|
|
94
|
+
* - follow(默认值): 不拦截重定向,即客户端自动处理重定向
|
|
95
|
+
* - manual: 拦截重定向。开启后,当 http 状态码为 3xx 时客户端不再自动重定向,而是触发 onHeadersReceived 回调,并结束本次 request 请求。可通过 onHeadersReceived 回调中的 header.Location 获取重定向的 url
|
|
96
|
+
*/
|
|
97
|
+
redirect?: "follow" | "manual";
|
|
98
|
+
/**
|
|
99
|
+
* 接口调用成功的回调函数
|
|
100
|
+
*/
|
|
101
|
+
success?: (res: IRequestSuccessCallbackResult) => void;
|
|
102
|
+
/**
|
|
103
|
+
* 接口调用失败的回调函数
|
|
104
|
+
*/
|
|
105
|
+
fail?: (err: IRequestFailCallbackResult) => void;
|
|
106
|
+
/**
|
|
107
|
+
* 接口调用结束的回调函数(调用成功、失败都会执行)
|
|
108
|
+
*/
|
|
109
|
+
complete?: Function;
|
|
110
|
+
}
|
|
111
|
+
export interface IGeneralCallbackResult {
|
|
112
|
+
/**
|
|
113
|
+
* 网络请求过程中的一些异常信息,例如httpdns超时等
|
|
114
|
+
*/
|
|
115
|
+
exception: {
|
|
116
|
+
/**
|
|
117
|
+
* 本次请求底层重试次数
|
|
118
|
+
*/
|
|
119
|
+
retryCount: number;
|
|
120
|
+
/**
|
|
121
|
+
* 本次请求底层失败信息,所有失败信息均符合Errno错误码
|
|
122
|
+
*/
|
|
123
|
+
reasons: Array<{
|
|
124
|
+
/**
|
|
125
|
+
* 错误原因
|
|
126
|
+
*/
|
|
127
|
+
errMsg: string;
|
|
128
|
+
/**
|
|
129
|
+
* 错误码
|
|
130
|
+
*/
|
|
131
|
+
errno: number;
|
|
132
|
+
}>;
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* 最终请求是否使用了HttpDNS解析的IP。仅当enableHttpDNS传true时返回此字段。如果开启enableHttpDNS但最终请求未使用HttpDNS解析的IP,可在exception查看原因。
|
|
136
|
+
*/
|
|
137
|
+
useHttpDNS: boolean;
|
|
138
|
+
}
|
|
139
|
+
export interface IRequestSuccessCallbackBaseResult {
|
|
140
|
+
/**
|
|
141
|
+
* 开发者服务器返回的数据
|
|
142
|
+
*/
|
|
143
|
+
data: string | object | ArrayBuffer;
|
|
144
|
+
/**
|
|
145
|
+
* 开发者服务器返回的 HTTP 状态码
|
|
146
|
+
*/
|
|
147
|
+
statusCode: number;
|
|
148
|
+
/**
|
|
149
|
+
* 开发者服务器返回的 HTTP Response Header
|
|
150
|
+
*/
|
|
151
|
+
header: object;
|
|
152
|
+
}
|
|
153
|
+
export interface IRequestSuccessCallbackResult extends IGeneralCallbackResult, IRequestSuccessCallbackBaseResult {
|
|
154
|
+
/**
|
|
155
|
+
* 开发者服务器返回的 cookies,格式为字符串数组
|
|
156
|
+
*/
|
|
157
|
+
cookies: string[];
|
|
158
|
+
/**
|
|
159
|
+
* 网络请求过程中一些调试信息。目前仅 iOS 和 Android 端支持,其他端暂不支持。
|
|
160
|
+
*/
|
|
161
|
+
profile: {
|
|
162
|
+
/**
|
|
163
|
+
* 调用接口的时间。
|
|
164
|
+
*/
|
|
165
|
+
invokeStart: number;
|
|
166
|
+
/**
|
|
167
|
+
* httpDNS 开始查询的时间。仅当开启 httpDNS 功能时返回该字段。目前仅wx.request接口支持
|
|
168
|
+
*/
|
|
169
|
+
httpDNSDomainLookUpStart: number;
|
|
170
|
+
/**
|
|
171
|
+
* httpDNS 完成查询的时间。仅当开启 httpDNS 功能时返回该字段。目前仅wx.request接口支持
|
|
172
|
+
*/
|
|
173
|
+
httpDNSDomainLookUpEnd: number;
|
|
174
|
+
/**
|
|
175
|
+
* 开始排队的时间。达到并行上限时才需要排队。
|
|
176
|
+
*/
|
|
177
|
+
queueStart: number;
|
|
178
|
+
/**
|
|
179
|
+
* 结束排队的时间。达到并行上限时才需要排队。如果未发生排队,则该字段和 queueStart 字段值相同
|
|
180
|
+
*/
|
|
181
|
+
queueEnd: number;
|
|
182
|
+
/**
|
|
183
|
+
* 第一个 HTTP 重定向发生时的时间。有跳转且是同域名内的重定向才算,否则值为 0
|
|
184
|
+
*/
|
|
185
|
+
redirectStart: number;
|
|
186
|
+
/**
|
|
187
|
+
* 最后一个 HTTP 重定向完成时的时间。有跳转且是同域名内部的重定向才算,否则值为 0
|
|
188
|
+
*/
|
|
189
|
+
redirectEnd: number;
|
|
190
|
+
/**
|
|
191
|
+
* 组件准备好使用 HTTP 请求抓取资源的时间,这发生在检查本地缓存之前
|
|
192
|
+
*/
|
|
193
|
+
fetchStart: number;
|
|
194
|
+
/**
|
|
195
|
+
* Local DNS 域名查询开始的时间,如果使用了本地缓存(即无 DNS 查询)或持久连接,则与 fetchStart 值相等
|
|
196
|
+
*/
|
|
197
|
+
domainLookUpStart: number;
|
|
198
|
+
/**
|
|
199
|
+
* Local DNS 域名查询完成的时间,如果使用了本地缓存(即无 DNS 查询)或持久连接,则与 fetchStart 值相等
|
|
200
|
+
*/
|
|
201
|
+
domainLookUpEnd: number;
|
|
202
|
+
/**
|
|
203
|
+
* HTTP(TCP) 开始建立连接的时间,如果是持久连接,则与 fetchStart 值相等。注意如果在传输层发生了错误且重新建立连接,则这里显示的是新建立的连接开始的时间
|
|
204
|
+
*/
|
|
205
|
+
connectStart: number;
|
|
206
|
+
/**
|
|
207
|
+
* HTTP(TCP) 完成建立连接的时间(完成握手),如果是持久连接,则与 fetchStart 值相等。注意如果在传输层发生了错误且重新建立连接,则这里显示的是新建立的连接完成的时间。注意这里握手结束,包括安全连接建立完成、SOCKS 授权通过
|
|
208
|
+
*/
|
|
209
|
+
connectEnd: number;
|
|
210
|
+
/**
|
|
211
|
+
* SSL建立连接的时间,如果不是安全连接,则值为 0
|
|
212
|
+
*/
|
|
213
|
+
SSLconnectionStart: number;
|
|
214
|
+
/**
|
|
215
|
+
* SSL建立完成的时间,如果不是安全连接,则值为 0
|
|
216
|
+
*/
|
|
217
|
+
SSLconnectionEnd: number;
|
|
218
|
+
/**
|
|
219
|
+
* HTTP请求读取真实文档开始的时间(完成建立连接),包括从本地读取缓存。连接错误重连时,这里显示的也是新建立连接的时间
|
|
220
|
+
*/
|
|
221
|
+
requestStart: number;
|
|
222
|
+
/**
|
|
223
|
+
* HTTP请求读取真实文档结束的时间
|
|
224
|
+
*/
|
|
225
|
+
requestEnd: number;
|
|
226
|
+
/**
|
|
227
|
+
* HTTP 开始接收响应的时间(获取到第一个字节),包括从本地读取缓存
|
|
228
|
+
*/
|
|
229
|
+
responseStart: number;
|
|
230
|
+
/**
|
|
231
|
+
* HTTP 响应全部接收完成的时间(获取到最后一个字节),包括从本地读取缓存
|
|
232
|
+
*/
|
|
233
|
+
responseEnd: number;
|
|
234
|
+
/**
|
|
235
|
+
* 当次请求连接过程中实时 rtt
|
|
236
|
+
*/
|
|
237
|
+
rtt: number;
|
|
238
|
+
/**
|
|
239
|
+
* 评估的网络状态 unknown, offline, slow 2g, 2g, 3g, 4g, last/0, 1, 2, 3, 4, 5, 6
|
|
240
|
+
*/
|
|
241
|
+
estimate_nettype: number;
|
|
242
|
+
/**
|
|
243
|
+
* 协议层根据多个请求评估当前网络的 rtt(仅供参考)
|
|
244
|
+
*/
|
|
245
|
+
httpRttEstimate: number;
|
|
246
|
+
/**
|
|
247
|
+
* 传输层根据多个请求评估的当前网络的 rtt(仅供参考)
|
|
248
|
+
*/
|
|
249
|
+
transportRttEstimate: number;
|
|
250
|
+
/**
|
|
251
|
+
* 评估当前网络下载的kbps
|
|
252
|
+
*/
|
|
253
|
+
downstreamThroughputKbpsEstimate: number;
|
|
254
|
+
/**
|
|
255
|
+
* 当前网络的实际下载kbps
|
|
256
|
+
*/
|
|
257
|
+
throughputKbps: number;
|
|
258
|
+
/**
|
|
259
|
+
* 当前请求的IP
|
|
260
|
+
*/
|
|
261
|
+
peerIP: string;
|
|
262
|
+
/**
|
|
263
|
+
* 当前请求的端口
|
|
264
|
+
*/
|
|
265
|
+
port: number;
|
|
266
|
+
/**
|
|
267
|
+
* 是否复用连接
|
|
268
|
+
*/
|
|
269
|
+
socketReused: boolean;
|
|
270
|
+
/**
|
|
271
|
+
* 发送的字节数
|
|
272
|
+
*/
|
|
273
|
+
sendBytesCount: number;
|
|
274
|
+
/**
|
|
275
|
+
* 收到字节数
|
|
276
|
+
*/
|
|
277
|
+
receivedBytedCount: number;
|
|
278
|
+
/**
|
|
279
|
+
* 使用协议类型,有效值:http1.1, h2, quic, unknown
|
|
280
|
+
*/
|
|
281
|
+
protocol: string;
|
|
282
|
+
/**
|
|
283
|
+
* 是否走到了高性能模式。基础库 v3.3.4 起支持。
|
|
284
|
+
*/
|
|
285
|
+
usingHighPerformanceMode: boolean;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
export interface IRequestFailCallbackResult extends IGeneralCallbackResult {
|
|
289
|
+
/**
|
|
290
|
+
* 错误信息
|
|
291
|
+
*/
|
|
292
|
+
errMsg: string;
|
|
293
|
+
/**
|
|
294
|
+
* errno 错误码
|
|
295
|
+
*/
|
|
296
|
+
errno: number;
|
|
297
|
+
}
|
|
298
|
+
export interface IAliRequestFailCallbackResult {
|
|
299
|
+
/**
|
|
300
|
+
* 错误码
|
|
301
|
+
*/
|
|
302
|
+
error: number;
|
|
303
|
+
/**
|
|
304
|
+
* 错误信息
|
|
305
|
+
*/
|
|
306
|
+
errorMessage: string;
|
|
307
|
+
/**
|
|
308
|
+
* 开发者服务器返回的数据,格式取决于请求时的 dataType 参数。
|
|
309
|
+
* 注意:当错误码为 14 或 19 时才会返回此字段
|
|
310
|
+
*/
|
|
311
|
+
data?: string | object | ArrayBuffer;
|
|
312
|
+
/**
|
|
313
|
+
* 开发者服务器返回的 HTTP 状态码
|
|
314
|
+
* 注意:当错误码为 14 或 19 时才会返回此字段
|
|
315
|
+
*/
|
|
316
|
+
status?: number;
|
|
317
|
+
/**
|
|
318
|
+
* 开发者服务器返回的 HTTP Response Header
|
|
319
|
+
* 注意:当错误码为 14 或 19 时才会返回此字段
|
|
320
|
+
*/
|
|
321
|
+
headers?: object;
|
|
322
|
+
}
|
|
323
|
+
export interface IRequestTask {
|
|
324
|
+
/**
|
|
325
|
+
* 中断请求任务
|
|
326
|
+
*/
|
|
327
|
+
abort: () => void;
|
|
328
|
+
/**
|
|
329
|
+
* 监听 HTTP Response Header 事件。会比请求完成事件更早
|
|
330
|
+
*/
|
|
331
|
+
onHeadersReceived: (listener: (res: {
|
|
332
|
+
/**
|
|
333
|
+
* 开发者服务器返回的 HTTP Response Header
|
|
334
|
+
*/
|
|
335
|
+
header: object;
|
|
336
|
+
/**
|
|
337
|
+
* 开发者服务器返回的 HTTP 状态码 (目前开发者工具上不会返回 statusCode 字段,可用真机查看该字段,后续将会支持)
|
|
338
|
+
*/
|
|
339
|
+
statusCode: number;
|
|
340
|
+
/**
|
|
341
|
+
* 开发者服务器返回的 cookies,格式为字符串数组
|
|
342
|
+
*/
|
|
343
|
+
cookies: string[];
|
|
344
|
+
}) => void) => void;
|
|
345
|
+
/**
|
|
346
|
+
* 移除 HTTP Response Header 事件的监听函数
|
|
347
|
+
*/
|
|
348
|
+
offHeadersReceived: (listener: Function) => void;
|
|
349
|
+
/**
|
|
350
|
+
* 监听 Transfer-Encoding Chunk Received 事件。当接收到新的chunk时触发。
|
|
351
|
+
*/
|
|
352
|
+
onChunkReceived: (listener: (res: {
|
|
353
|
+
/**
|
|
354
|
+
* 返回的chunk buffer
|
|
355
|
+
*/
|
|
356
|
+
data: ArrayBuffer;
|
|
357
|
+
}) => void) => void;
|
|
358
|
+
/**
|
|
359
|
+
* 移除 Transfer-Encoding Chunk Received 事件的监听函数
|
|
360
|
+
*/
|
|
361
|
+
offChunkReceived: (listener: Function) => void;
|
|
362
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mphttpx",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "rollup --config",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"author": "Xingzeng",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"description": "",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"mini-program",
|
|
21
|
+
"polyfill"
|
|
22
|
+
],
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
25
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
26
|
+
"rollup": "^4.53.1",
|
|
27
|
+
"rollup-plugin-dts": "^6.3.0",
|
|
28
|
+
"tslib": "^2.8.1"
|
|
29
|
+
}
|
|
30
|
+
}
|