@whitesev/utils 2.3.7 → 2.4.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.
Files changed (57) hide show
  1. package/dist/index.amd.js +415 -289
  2. package/dist/index.amd.js.map +1 -1
  3. package/dist/index.cjs.js +415 -289
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.esm.js +415 -289
  6. package/dist/index.esm.js.map +1 -1
  7. package/dist/index.iife.js +415 -289
  8. package/dist/index.iife.js.map +1 -1
  9. package/dist/index.system.js +415 -289
  10. package/dist/index.system.js.map +1 -1
  11. package/dist/index.umd.js +415 -289
  12. package/dist/index.umd.js.map +1 -1
  13. package/dist/types/src/Httpx.d.ts +25 -1178
  14. package/dist/types/src/Log.d.ts +1 -19
  15. package/dist/types/src/Progress.d.ts +1 -20
  16. package/dist/types/src/TryCatch.d.ts +2 -11
  17. package/dist/types/src/Utils.d.ts +8 -32
  18. package/dist/types/src/UtilsGMCookie.d.ts +1 -51
  19. package/dist/types/src/UtilsGMMenu.d.ts +1 -50
  20. package/dist/types/src/WindowApi.d.ts +3 -11
  21. package/dist/types/src/types/Httpx.d.ts +1316 -0
  22. package/dist/types/src/types/Log.d.ts +19 -0
  23. package/dist/types/src/types/Progress.d.ts +20 -0
  24. package/dist/types/src/types/TryCatch.d.ts +9 -0
  25. package/dist/types/src/types/UtilsGMCookie.d.ts +55 -0
  26. package/dist/types/src/types/UtilsGMMenu.d.ts +77 -0
  27. package/{src/VueObject.ts → dist/types/src/types/Vue2.d.ts} +28 -15
  28. package/dist/types/src/types/Vue3.d.ts +0 -0
  29. package/dist/types/src/types/WindowApi.d.ts +10 -0
  30. package/dist/types/src/types/global.d.ts +24 -1
  31. package/package.json +1 -1
  32. package/src/GBKEncoder.ts +1 -1
  33. package/src/Httpx.ts +535 -1627
  34. package/src/Log.ts +1 -19
  35. package/src/Progress.ts +1 -20
  36. package/src/TryCatch.ts +2 -12
  37. package/src/Utils.ts +44 -66
  38. package/src/UtilsGMCookie.ts +7 -56
  39. package/src/UtilsGMMenu.ts +5 -78
  40. package/src/WindowApi.ts +4 -11
  41. package/src/indexedDB.ts +12 -10
  42. package/src/types/Event.d.ts +189 -0
  43. package/src/types/Httpx.d.ts +1316 -0
  44. package/src/types/Log.d.ts +19 -0
  45. package/src/types/Progress.d.ts +20 -0
  46. package/src/types/TryCatch.d.ts +9 -0
  47. package/src/types/UtilsGMCookie.d.ts +55 -0
  48. package/src/types/UtilsGMMenu.d.ts +77 -0
  49. package/src/types/Vue2.d.ts +154 -0
  50. package/src/types/Vue3.d.ts +0 -0
  51. package/src/types/WindowApi.d.ts +10 -0
  52. package/{dist/types/src/AjaxHookerType.d.ts → src/types/ajaxHooker.d.ts} +155 -147
  53. package/src/types/global.d.ts +24 -1
  54. package/dist/types/src/Event.d.ts +0 -156
  55. package/dist/types/src/VueObject.d.ts +0 -123
  56. /package/{src/Event.ts → dist/types/src/types/Event.d.ts} +0 -0
  57. /package/{src/AjaxHookerType.ts → dist/types/src/types/ajaxHooker.d.ts} +0 -0
package/src/Httpx.ts CHANGED
@@ -1,1256 +1,15 @@
1
+ import type {
2
+ HttpxAllowInterceptConfig,
3
+ HttpxHookErrorData,
4
+ HttpxMethod,
5
+ HttpxRequestOption,
6
+ HttpxRequestOptionConfig,
7
+ HttpxResponse,
8
+ HttpxResponseData,
9
+ } from "./types/Httpx";
1
10
  import { Utils } from "./Utils";
2
11
  import { GenerateUUID } from "./UtilsCommon";
3
12
 
4
- /**
5
- * 状态码
6
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Status
7
- */
8
- export type HttpxStatus =
9
- | 100
10
- | 101
11
- | 102
12
- | 103
13
- | 200
14
- | 201
15
- | 202
16
- | 203
17
- | 204
18
- | 205
19
- | 206
20
- | 207
21
- | 208
22
- | 300
23
- | 301
24
- | 302
25
- | 304
26
- | 307
27
- | 308
28
- | 401
29
- | 402
30
- | 403
31
- | 404
32
- | 405
33
- | 406
34
- | 407
35
- | 408
36
- | 409
37
- | 410
38
- | 411
39
- | 412
40
- | 413
41
- | 414
42
- | 415
43
- | 416
44
- | 417
45
- | 418
46
- | 421
47
- | 422
48
- | 423
49
- | 424
50
- | 425
51
- | 426
52
- | 428
53
- | 429
54
- | 431
55
- | 451
56
- | 500
57
- | 501
58
- | 502
59
- | 503
60
- | 504
61
- | 505
62
- | 506
63
- | 507
64
- | 508
65
- | 510
66
- | 511;
67
-
68
- /**
69
- * HTTP 请求方法
70
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Methods
71
- */
72
- export type HttpxMethod =
73
- | "GET"
74
- | "HEAD"
75
- | "POST"
76
- | "PUT"
77
- | "DELETE"
78
- | "CONNECT"
79
- | "OPTIONS"
80
- | "TRACE"
81
- | "PATCH";
82
-
83
- export type HttpxRedirect = "follow" | "error" | "manual";
84
-
85
- export type HttpxBinary =
86
- | Uint8ArrayConstructor
87
- | ArrayBufferConstructor
88
- | DataViewConstructor
89
- | Blob
90
- | File;
91
-
92
- export type HttpxResponseCallBackType =
93
- | "onload"
94
- | "onerror"
95
- | "ontimeout"
96
- | "onabort";
97
-
98
- export type HttpxResponseMap = {
99
- arraybuffer: ArrayBuffer;
100
- blob: Blob;
101
- json: any;
102
- stream: ReadableStream<string>;
103
- document: Document;
104
- undefined: string;
105
- html: string;
106
- };
107
-
108
- /**
109
- * headers的配置
110
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers
111
- */
112
- export declare interface HttpxHeaders {
113
- /**
114
- * Accept 请求头用来告知(服务器)客户端可以处理的内容类型,这种内容类型用MIME 类型来表示。
115
- * 借助内容协商机制, 服务器可以从诸多备选项中选择一项进行应用,并使用 Content-Type 应答头通知客户端它的选择。
116
- * 浏览器会基于请求的上下文来为这个请求头设置合适的值,比如获取一个 CSS 层叠样式表时值与获取图片、视频或脚本文件时的值是不同的。
117
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept
118
- */
119
- Accept?: string;
120
- /**
121
- * 头由服务器设置,以指定客户端应在后续请求中应包含哪些客户端 Client Hints (en-US) 提示头
122
- * + 备注: Client Hints (en-US) 只能在安全源(通过 TLS)上访问。所有安全的请求都应该持久化 Accept-CH 和 Accept-CH-Lifetime 头,以确保 Client Hints (en-US) 可靠地发送。
123
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-CH
124
- * @deprecated
125
- */
126
- "Accept-CH"?: string;
127
- /**
128
- * 服务器设置 Accept-CH-Lifetime 标头以指定Accept-CH标头值的持久性,该值指定客户端应在后续请求中包括哪些Client Hints (en-US)标头。
129
- * + 备注: Client Hints (en-US)只能在安全源(通过 TLS)上访问。所有安全的请求都应该持久化 Accept-CH 和 Accept-CH-Lifetime 头,以确保Client Hints (en-US)可靠地发送。
130
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-CH-Lifetime
131
- * @deprecated
132
- */
133
- "Accept-CH-Lifetime"?: string;
134
- /**
135
- * Accept-Charset 请求头用来告知(服务器)客户端可以处理的字符集类型。
136
- * 借助内容协商机制,服务器可以从诸多备选项中选择一项进行应用,并使用Content-Type 应答头通知客户端它的选择。
137
- * 浏览器通常不会设置此项值,因为每种内容类型的默认值通常都是正确的,但是发送它会更有利于识别。
138
- * 如果服务器不能提供任何可以匹配的字符集的版本,那么理论上来说应该返回一个 406(Not Acceptable,不被接受)的错误码。
139
- * 但是为了更好的用户体验,这种方法很少采用,取而代之的是将其忽略。
140
- * + 备注: 在早期版本的 HTTP/1.1 协议中,规定了一个默认的字符集 (ISO-8859-1)。但是现在情况不同了,目前每一种内容类型都有自己的默认字符集。
141
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-Charset
142
- */
143
- "Accept-Charset"?: string;
144
- /**
145
- * HTTP 请求头 Accept-Encoding 会将客户端能够理解的内容编码方式——通常是某种压缩算法——进行通知(给服务端)。
146
- * 通过内容协商的方式,服务端会选择一个客户端提议的方式,使用并在响应头 Content-Encoding 中通知客户端该选择。
147
- * 即使客户端和服务器都支持相同的压缩算法,在 identity 指令可以被接受的情况下,服务器也可以选择对响应主体不进行压缩。导致这种情况出现的两种常见的情形是:
148
- * + 要发送的数据已经经过压缩,再次进行压缩不会导致被传输的数据量更小。一些图像格式的文件会存在这种情况;
149
- * + 服务器超载,无法承受压缩需求导致的计算开销。通常,如果服务器使用超过 80% 的计算能力,微软建议不要压缩。
150
- *
151
- * 只要 identity——表示不需要进行任何编码——没有被明确禁止使用(通过 identity;q=0 指令或是 *;q=0 而没有为 identity 明确指定权重值),则服务器禁止返回表示客户端错误的 406 Not Acceptable 响应。
152
- * + 备注: IANA 维护了一个完整的官方支持的编码方式列表。
153
- * 另外两种编码方式——bzip 和 bzip2——有时候也会用到,尽管并未在标准中出现。这两种方式实现了 UNIX 系统上的同名程序所采用的算法。注意第一种由于专利许可问题已经停止维护。
154
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-Encoding
155
- */
156
- "Accept-Encoding"?: string;
157
- /**
158
- * Accept-Language 请求头允许客户端声明它可以理解的自然语言,以及优先选择的区域方言。
159
- * 借助内容协商机制,服务器可以从诸多备选项中选择一项进行应用,并使用 Content-Language 应答头通知客户端它的选择。
160
- * 浏览器会基于其用户界面语言为这个请求头设置合适的值,即便是用户可以进行修改,但是这种情况极少发生(因为可增加指纹独特性,通常也不被鼓励)
161
- * (译者注:通常只在测试网站的多语言支持时手动修改它;或为进一步减少指纹独特性,改为最常见的英文)。
162
- * 当服务器无法通过其他方式来确定应当使用的语言时——例如某一特定的 URL,这是用户明确指定的——这个请求头可以用作提示。建议服务器端永远不要覆盖明确指定的信息。
163
- * Accept-Language 消息头的内容通常不在用户的掌控之中(例如在国外旅行时到提供网络服务的场所上网);
164
- * 另外用户可能会想要浏览非本地用户界面语言的页面。
165
- * 如果服务器不能提供任何可以匹配的语言的版本,那么理论上来说应该返回一个 406(Not Acceptable,不被接受)的错误码。
166
- * 但是为了更好的用户体验,这种方法很少被采用,取而代之的是将其忽略。
167
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-Language
168
- *
169
- */
170
- "Accept-Language"?: string;
171
- /**
172
- * 服务器使用 HTTP 响应头 Accept-Patch 通知浏览器请求的媒体类型 (media-type) 可以被服务器理解。
173
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-Patch
174
- */
175
- "Accept-Patch"?: string;
176
- /**
177
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-Post
178
- */
179
- "Accept-Post"?: string;
180
- /**
181
- * 服务器使用 HTTP 响应头 Accept-Ranges 标识自身支持范围请求 (partial requests)。字段的具体值用于定义范围请求的单位。
182
- * 当浏览器发现Accept-Ranges头时,可以尝试继续中断了的下载,而不是重新开始。
183
- *
184
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Accept-Ranges
185
- */
186
- "Accept-Ranges"?: "bytes" | "none";
187
- /**
188
- * Access-Control-Allow-Credentials 响应头用于在请求要求包含 credentials(Request.credentials 的值为 include)时,告知浏览器是否可以将对请求的响应暴露给前端 JavaScript 代码。
189
- * 当请求的 credentials 模式(Request.credentials)为 include 时,浏览器仅在响应标头 Access-Control-Allow-Credentials 的值为 true 的情况下将响应暴露给前端的 JavaScript 代码。
190
- * Credentials 可以是 cookies、authorization headers 或 TLS client certificates。
191
- * 当作为对预检请求的响应的一部分时,这能表示是否真正的请求可以使用 credentials。
192
- * 注意简单的GET 请求没有预检,所以若一个对资源的请求带了 credentials,如果这个响应头没有随资源返回,响应就会被浏览器忽视,不会返回到 web 内容。
193
- * Access-Control-Allow-Credentials 标头需要与 XMLHttpRequest.withCredentials 或 Fetch API 的 Request() 构造函数中的 credentials 选项结合使用。
194
- * Credentials 必须在前后端都被配置(即 Access-Control-Allow-Credentials header 和 XHR 或 Fetch request 中都要配置)才能使带 credentials 的 CORS 请求成功。
195
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials
196
- */
197
- "Access-Control-Allow-Credentials"?: "true";
198
- /**
199
- * 响应首部 Access-Control-Allow-Headers 用于 preflight request(预检请求)中,列出了将会在正式请求的 Access-Control-Request-Headers 字段中出现的首部信息。
200
- * 简单首部,如 simple headers、Accept、Accept-Language、Content-Language、Content-Type(只限于解析后的值为 application/x-www-form-urlencoded、multipart/form-data 或 text/plain 三种 MIME 类型(不包括参数)),它们始终是被支持的,不需要在这个首部特意列出。
201
- * 如果请求中含有 Access-Control-Request-Headers 字段,那么这个首部是必要的。
202
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Allow-Headers
203
- */
204
- "Access-Control-Allow-Headers"?: string;
205
- /**
206
- * 响应首部 Access-Control-Allow-Methods 在对 preflight request.(预检请求)的应答中明确了客户端所要访问的资源允许使用的方法或方法列表。
207
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Allow-Methods
208
- */
209
- "Access-Control-Allow-Methods"?: string;
210
- /**
211
- * Access-Control-Allow-Origin 响应标头指定了该响应的资源是否被允许与给定的来源(origin)共享。
212
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Allow-Origin
213
- */
214
- "Access-Control-Allow-Origin"?: "*" | "<origin>" | "null";
215
- /**
216
- * 响应标头 Access-Control-Expose-Headers 允许服务器指示那些响应标头可以暴露给浏览器中运行的脚本,以响应跨源请求。
217
- * 默认情况下,仅暴露 CORS 安全列表的响应标头 (en-US)。
218
- * 如果想要让客户端可以访问到其他的标头,服务器必须将它们在 Access-Control-Expose-Headers 里面列出来。
219
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers
220
- */
221
- "Access-Control-Expose-Headers"?: string;
222
- /**
223
- * The Access-Control-Max-Age 这个响应头表示 preflight request (预检请求)的返回结果(即 Access-Control-Allow-Methods 和Access-Control-Allow-Headers 提供的信息)可以被缓存多久。
224
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Max-Age
225
- */
226
- "Access-Control-Max-Age"?: string;
227
- /**
228
- * 请求头 Access-Control-Request-Headers 出现于 preflight request(预检请求)中,用于通知服务器在真正的请求中会采用哪些请求头。
229
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Request-Headers
230
- */
231
- "Access-Control-Request-Headers"?: string;
232
- /**
233
- * 请求头 Access-Control-Request-Method 出现于 preflight request(预检请求)中,用于通知服务器在真正的请求中会采用哪种 HTTP 方法。因为预检请求所使用的方法总是 OPTIONS ,与实际请求所使用的方法不一样,所以这个请求头是必要的。
234
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Request-Method
235
- */
236
- "Access-Control-Request-Method"?: HttpxMethod;
237
- /**
238
- * Age 消息头里包含对象在缓存代理中存贮的时长,以秒为单位。
239
- * Age 的值通常接近于 0。表示此对象刚刚从原始服务器获取不久;其他的值则是表示代理服务器当前的系统时间与此应答中的通用头 Date 的值之差。
240
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Age
241
- */
242
- Age?: string;
243
- /**
244
- * Allow 首部字段用于枚举资源所支持的 HTTP 方法的集合。
245
- * 若服务器返回状态码 405 Method Not Allowed,则该首部字段亦需要同时返回给客户端。
246
- * 如果 Allow 首部字段的值为空,说明资源不接受使用任何 HTTP 方法的请求。
247
- * 这是可能的,比如服务器需要临时禁止对资源的任何访问。
248
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Allow
249
- */
250
- Allow?: string;
251
- /**
252
- * Alt-Svc 全称为“Alternative-Service”,直译为“备选服务”。
253
- * 该头部列举了当前站点备选的访问方式列表。一般用于在提供“QUIC”等新兴协议支持的同时,实现向下兼容。
254
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Alt-Svc
255
- */
256
- "Alt-Svc"?: string;
257
- /**
258
- *
259
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Alt-Used
260
- */
261
- "Alt-Used"?: string;
262
- /**
263
- * HTTP Authorization 请求标头用于提供服务器验证用户代理身份的凭据,允许访问受保护的资源。
264
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Authorization
265
- */
266
- Authorization?: string;
267
- /**
268
- * Cache-Control 通用消息头字段,被用于在 http 请求和响应中,通过指定指令来实现缓存机制。缓存指令是单向的,这意味着在请求中设置的指令,不一定被包含在响应中。
269
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cache-Control
270
- */
271
- "Cache-Control"?: string;
272
- /**
273
- * Clear-Site-Data 响应头,表示清除当前请求网站有关的浏览器数据(cookie,存储,缓存)。它让 Web 开发人员对浏览器本地存储的数据有更多控制能力。
274
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Clear-Site-Data
275
- */
276
- "Clear-Site-Data"?: string;
277
- /**
278
- * Connection 通用标头控制网络连接在当前会话完成后是否仍然保持打开状态。如果发送的值是 keep-alive,则连接是持久的,不会关闭,允许对同一服务器进行后续请求。
279
- * 除去标准的逐段传输(hop-by-hop)头(Keep-Alive, Transfer-Encoding, TE, Connection, Trailer, Upgrade (en-US), Proxy-Authorization and Proxy-Authenticate),任何逐段传输头都需要在 Connection 头中列出,这样才能让第一个代理知道必须处理它们且不转发这些头。
280
- * 标准的逐段传输头也可以列出(常见的例子是 Keep-Alive,但这不是必须的)。
281
- * + 警告: 在 HTTP/2 和 HTTP/3 中,禁止使用特定于连接的标头字段,如 Connection 和 Keep-Alive。
282
- * Chrome 和 Firefox 会在 HTTP/2 响应中忽略它们,但 Safari 遵循 HTTP/2 规范要求,不会加载包含这些字段的任何响应。
283
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Connection
284
- * @deprecated
285
- */
286
- Connection?: "keep-alive" | "close";
287
- /**
288
- * 在常规的 HTTP 应答中,Content-Disposition 响应标头指示回复的内容该以何种形式展示,是以内联的形式(即网页或者页面的一部分),还是以附件的形式下载并保存到本地。
289
- *
290
- * 在 multipart/form-data 类型的应答消息体中,Content-Disposition 通用标头可以被用在 multipart 消息体的子部分中,用来给出其对应字段的相关信息。
291
- * 各个子部分由在 Content-Type 中定义的边界(boundary)分隔。用在消息体自身则无实际意义。
292
- *
293
- * Content-Disposition 标头最初是在 MIME 标准中定义的,HTTP 表单及 POST 请求只用到了其所有参数的一个子集。
294
- * 只有 form-data 以及可选的 name 和 filename 三个参数可以应用在 HTTP 上下文中。
295
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Disposition
296
- */
297
- "Content-Disposition"?: string;
298
- /**
299
- *
300
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-DPR
301
- * @deprecated
302
- */
303
- "Content-DPR"?: string;
304
- /**
305
- * 实体消息首部 Content-Encoding 列出了对当前实体消息(消息荷载)应用的任何编码类型,以及编码的顺序。
306
- * 它让接收者知道需要以何种顺序解码该实体消息才能获得原始荷载格式。
307
- * Content-Encoding 主要用于在不丢失原媒体类型内容的情况下压缩消息数据。
308
- *
309
- * 请注意原始媒体/内容的类型通过 Content-Type 首部给出,而 Content-Encoding 应用于数据的表示,或“编码形式”。
310
- * 如果原始媒体以某种方式编码(例如 zip 文件),则该信息不应该被包含在 Content-Encoding 首部内。
311
- *
312
- * 一般建议服务器应对数据尽可能地进行压缩,并在适当情况下对内容进行编码。
313
- * 对一种压缩过的媒体类型如 zip 或 jpeg 进行额外的压缩并不合适,因为这反而有可能会使荷载增大。
314
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Encoding
315
- */
316
- "Content-Encoding"?: "gzip" | "compress" | "deflate" | "br";
317
- /**
318
- * Content-Language 是一个 entity header(实体消息首部),用来说明访问者希望采用的语言或语言组合,这样的话用户就可以根据自己偏好的语言来定制不同的内容。
319
- *
320
- * 举个例子,假如设置了这样一条消息首部( "Content-Language: de-DE" ),那么说明这份文件是为说德语的人提供的(当然这并不意味着文件本身就是用德语写的。
321
- * 比如,它可能是为说德语的人开设的英语教程的一部分,也就是用英语写的)。
322
- *
323
- * 如果没有指明 Content-Language,那么默认地,文件内容是提供给所有语言的访问者使用的。
324
- * 多个语言标签也是合法的,同样的,这个首部还可以用来描述不同媒体类型的文件,而不单单局限于文本型文档。
325
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Language
326
- */
327
- "Content-Language"?: string;
328
- /**
329
- * Content-Length 是一个实体消息首部,用来指明发送给接收方的消息主体的大小,即用十进制数字表示的八位元组的数目。
330
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Length
331
- */
332
- "Content-Length"?: string;
333
- /**
334
- * Content-Location 首部指定的是要返回的数据的地址选项。
335
- * 最主要的用途是用来指定要访问的资源经过内容协商后的结果的 URL。
336
- *
337
- * Location 与 Content-Location是不同的,前者(Location )指定的是一个重定向请求的目的地址(或者新创建的文件的 URL),而后者( Content-Location)指向的是可供访问的资源的直接地址,不需要进行进一步的内容协商。
338
- * Location 对应的是响应,而 Content-Location 对应的是要返回的实体。
339
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Location
340
- */
341
- "Content-Location"?: string;
342
- /**
343
- * 在 HTTP 协议中,响应首部 Content-Range 显示的是一个数据片段在整个文件中的位置。
344
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Range
345
- */
346
- "Content-Range"?: string;
347
- /**
348
- * HTTP 响应头 Content-Security-Policy 允许站点管理者控制用户代理能够为指定的页面加载哪些资源。
349
- * 除了少数例外情况,设置的政策主要涉及指定服务器的源和脚本结束点。
350
- * 这将帮助防止跨站脚本攻击(Cross-Site Script)(XSS (en-US))。
351
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Security-Policy
352
- */
353
- "Content-Security-Policy"?: string;
354
- /**
355
- * HTTP **Content-Security-Policy-Report-Only**响应头允许 web 开发人员通过监测 (但不强制执行) 政策的影响来尝试政策。
356
- * 这些违反报告由 JSON 文档组成通过一个 HTTP POST 请求发送到指定的 URI。
357
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
358
- */
359
- "Content-Security-Policy-Report-Only"?: string;
360
- /**
361
- * Content-Type 实体头部用于指示资源的 MIME 类型 media type 。
362
- *
363
- * 在响应中,Content-Type 标头告诉客户端实际返回的内容的内容类型。
364
- * 浏览器会在某些情况下进行 MIME 查找,并不一定遵循此标题的值;
365
- * 为了防止这种行为,可以将标题 X-Content-Type-Options 设置为 nosniff
366
- *
367
- * 在请求中 (如POST 或 PUT),客户端告诉服务器实际发送的数据类型。
368
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Content-Type
369
- */
370
- "Content-Type"?:
371
- | "text/html; charset=utf-8"
372
- | "multipart/form-data"
373
- | "application/x-www-form-urlencoded"
374
- | "application/json"
375
- | string;
376
- /**
377
- * Cookie 是一个 HTTP 请求标头,其中含有先前由服务器通过 Set-Cookie 标头投放或通过 JavaScript 的 Document.cookie 方法设置,然后存储到客户端的 HTTP cookie 。
378
- * 这个标头是可选的,而且可能会被忽略,例如在浏览器的隐私设置里面设置为禁用 cookie。
379
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cookie
380
- */
381
- Cookie?: string;
382
- /**
383
- *
384
- * + https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Critical-CH
385
- * @deprecated
386
- */
387
- "Critical-CH"?: string;
388
- /**
389
- * HTTP Cross-Origin-Embedder-Policy (COEP) 响应标头可防止文档加载未明确授予文档权限 (通过 CORP (en-US) 或者 CORS) 的任何跨域资源。
390
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cross-Origin-Embedder-Policy
391
- */
392
- "Cross-Origin-Embedder-Policy"?: string;
393
- /**
394
- *
395
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cross-Origin-Opener-Policy
396
- */
397
- "Cross-Origin-Opener-Policy"?: string;
398
- /**
399
- * + 备注: 由于Chrome 浏览器中的一个 Bug, 设置 Cross-Origin-Resource-Policy(跨域资源策略)会使文件下载失败:当从设置了 CORP 请求头的资源服务器下载资源时,浏览器会阻止用户使用“保存”或“另存为”按钮将文件保存到本地。在决定生产环境中是否使用这一特性(CORP)之前需要慎重考虑。
400
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy
401
- */
402
- "Cross-Origin-Resource-Policy"?: string;
403
- /**
404
- * Date 是一个通用首部,其中包含了报文创建的日期和时间。
405
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Date
406
- */
407
- Date?: string;
408
- /**
409
- * Device-Memory 是一个跟 Device Memory API (en-US) 相关的请求头,它跟 Client Hints (en-US) 请求头的作用相似,用来表示客户端设备内存的近似大小。
410
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Device-Memory
411
- * @deprecated
412
- */
413
- "Device-Memory"?: string;
414
- /**
415
- * Digest 响应 HTTP 头提供了请求资源一个 摘要 。
416
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Digest
417
- */
418
- Digest?: string;
419
- /**
420
- * navigator.doNotTrack
421
- *
422
- * 请求首部 DNT (Do Not Track) 表明了用户对于网站追踪的偏好。它允许用户指定自己是否更注重个人隐私还是定制化内容。
423
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/DNT
424
- * + 0 表示用户愿意目标站点追踪用户个人信息。
425
- * + 1 表示用户不愿意目标站点追踪用户个人信息。
426
- * @deprecated
427
- */
428
- DNT?: "0" | "1";
429
- /**
430
- *
431
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Downlink
432
- */
433
- Downlink?: string;
434
- /**
435
- * **DPR**请求头是“ 客户端提示” (en-US)消息头,它代表客户端设备的像素比 (DPR),该比例是与每个 CSS 像素相对应的物理设备像素的数量。
436
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/DPR
437
- * @deprecated
438
- */
439
- DPR?: string;
440
- /**
441
- * Early-Data 头(header)由某个中间者设置来表示请求已在 TLS early data 中传送,且表示 某个中间者理解 425 (Too Early) 状态码。
442
- * Early-Data 头(header)不由请求的发起者设置 (例如,浏览器)。
443
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Early-Data
444
- * @deprecated
445
- */
446
- "Early-Data"?: "1";
447
- /**
448
- *
449
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/ECT
450
- * @deprecated
451
- */
452
- ECT?: string;
453
- /**
454
- * ETag HTTP 响应头是资源的特定版本的标识符。这可以让缓存更高效,并节省带宽,因为如果内容没有改变,Web 服务器不需要发送完整的响应。
455
- * 而如果内容发生了变化,使用 ETag 有助于防止资源的同时更新相互覆盖(“空中碰撞”)。
456
- *
457
- * 如果给定 URL 中的资源更改,则一定要生成新的 ETag 值。比较这些 ETag 能快速确定此资源是否变化。
458
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/ETag
459
- */
460
- ETag?: string;
461
- /**
462
- * Expect 是一个请求消息头,包含一个期望条件,表示服务器只有在满足此期望条件的情况下才能妥善地处理请求。
463
- *
464
- * 规范中只规定了一个期望条件,即 Expect: 100-continue, 对此服务器可以做出如下回应:
465
- * + 100 如果消息头中的期望条件可以得到满足,使得请求可以顺利进行的话,
466
- * + 417 (Expectation Failed) 如果服务器不能满足期望条件的话;也可以是其他任意表示客户端错误的状态码(4xx)。
467
- *
468
- * 例如,如果请求中 Content-Length 的值太大的话,可能会遭到服务器的拒绝。
469
- *
470
- * 常见的浏览器不会发送 Expect 消息头,但是其他类型的客户端如 cURL 默认会这么做。
471
- *
472
- *
473
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Expect
474
- */
475
- Expect?: string;
476
- /**
477
- * Expect-CT 标头允许站点选择性地报告和/或执行证书透明度(Certificate Transparency)要求,来防止错误签发的网站证书的使用不被察觉。
478
- *
479
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Expect-CT
480
- */
481
- "Expect-CT"?: string;
482
- /**
483
- * Expires 响应头包含日期/时间,即在此时候之后,响应过期。
484
- *
485
- * 无效的日期,比如 0,代表着过去的日期,即该资源已经过期。
486
- *
487
- * 如果在Cache-Control响应头设置了 "max-age" 或者 "s-max-age" 指令,那么 Expires 头会被忽略。
488
- *
489
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Expires
490
- */
491
- Expires?: string;
492
- /**
493
- * Forwarded 首部中包含了代理服务器的客户端的信息,即由于代理服务器在请求路径中的介入而被修改或丢失的信息。
494
- *
495
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Forwarded
496
- */
497
- Forwarded?: string;
498
- /**
499
- * 请求首部 From 中包含一个电子邮箱地址,这个电子邮箱地址属于发送请求的用户代理的实际掌控者的人类用户。
500
- *
501
- * 如果你在运行一个机器人代理程序(比如爬虫),那么 Form 首部应该随请求一起发送,这样的话,在服务器遇到问题的时候,例如机器人代理发送了过量的、不希望收到的或者不合法的请求,站点管理员可以联系到你。
502
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/From
503
- */
504
- From?: string;
505
- /**
506
- * Host 请求头指明了请求将要发送到的服务器主机名和端口号。
507
- *
508
- * 如果没有包含端口号,会自动使用被请求服务的默认端口(比如 HTTPS URL 使用 443 端口,HTTP URL 使用 80 端口)。
509
- *
510
- * 所有 HTTP/1.1 请求报文中必须包含一个Host头字段。对于缺少Host头或者含有超过一个Host头的 HTTP/1.1 请求,可能会收到400(Bad Request)状态码。
511
- *
512
- *
513
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Host
514
- */
515
- Host?: string;
516
- /**
517
- * 请求首部 If-Match 的使用表示这是一个条件请求。在请求方法为 GET 和 HEAD 的情况下,服务器仅在请求的资源满足此首部列出的 ETag值时才会返回资源。
518
- * 而对于 PUT 或其他非安全方法来说,只有在满足条件的情况下才可以将资源上传。
519
- *
520
- *
521
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/If-Match
522
- */
523
- "If-Match"?: string;
524
- /**
525
- * If-Modified-Since 是一个条件式请求首部,服务器只在所请求的资源在给定的日期时间之后对内容进行过修改的情况下才会将资源返回,状态码为 200 。
526
- * 如果请求的资源从那时起未经修改,那么返回一个不带有消息主体的 304 响应,而在 Last-Modified 首部中会带有上次修改时间。
527
- * 不同于 If-Unmodified-Since, If-Modified-Since 只可以用在 GET 或 HEAD 请求中。
528
- *
529
- * 当与 If-None-Match 一同出现时,它(If-Modified-Since)会被忽略掉,除非服务器不支持 If-None-Match。
530
- *
531
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/If-Modified-Since
532
- */
533
- "If-Modified-Since"?: string;
534
- /**
535
- * If-None-Match 是一个条件式请求首部。
536
- * 对于 GETGET 和 HEAD 请求方法来说,当且仅当服务器上没有任何资源的 ETag 属性值与这个首部中列出的相匹配的时候,服务器端才会返回所请求的资源,响应码为 200 。
537
- * 对于其他方法来说,当且仅当最终确认没有已存在的资源的 ETag 属性值与这个首部中所列出的相匹配的时候,才会对请求进行相应的处理。
538
- *
539
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/If-None-Match
540
- */
541
- "If-None-Match"?: string;
542
- /**
543
- * If-Range HTTP 请求头字段用来使得 Range 头字段在一定条件下起作用:
544
- * 当字段值中的条件得到满足时,Range 头字段才会起作用,同时服务器回复206 部分内容状态码,以及**Range** 头字段请求的相应部分;
545
- * 如果字段值中的条件没有得到满足,服务器将会返回 200 OK 状态码,并返回完整的请求资源。
546
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/If-Range
547
- */
548
- "If-Range"?: string;
549
- /**
550
- * HTTP 协议中的 If-Unmodified-Since 消息头用于请求之中,使得当前请求成为条件式请求:
551
- * 只有当资源在指定的时间之后没有进行过修改的情况下,服务器才会返回请求的资源,或是接受 POST 或其他 non-safe 方法的请求。
552
- * 如果所请求的资源在指定的时间之后发生了修改,那么会返回 412 (Precondition Failed) 错误。
553
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/
554
- */
555
- "If-Unmodified-Since"?: string;
556
- /**
557
- * Keep-Alive 是一个通用消息头,允许消息发送者暗示连接的状态,还可以用来设置超时时长和最大请求数。
558
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Keep-Alive
559
- */
560
- "Keep-Alive"?: string;
561
- /**
562
- * 非标准的**Large-Allocation** 响应头部是用来告诉浏览器加载该页面可能需要申请大内存。当前只有 Firefox 实现该特性,但是对其他浏览器也无损害。
563
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Large-Allocation
564
- * @deprecated
565
- */
566
- "Large-Allocation"?: string;
567
- /**
568
- * Last-Modified 是一个响应首部,其中包含源头服务器认定的资源做出修改的日期及时间。它通常被用作一个验证器来判断接收到的或者存储的资源是否彼此一致。
569
- * 由于精确度比 ETag 要低,所以这是一个备用机制。包含有 If-Modified-Since 或 If-Unmodified-Since 首部的条件请求会使用这个字段。
570
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Last-Modified
571
- */
572
- "Last-Modified"?: string;
573
- /**
574
- * HTTP 实体报头 Link 提供了序列化 HTTP 头部链接的方法。
575
- * 它在语义上与 HTML 元素 <link> 相等。
576
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Link
577
- */
578
- Link?: string;
579
- /**
580
- * Location 首部指定的是需要将页面重新定向至的地址。
581
- * 一般在响应码为 3xx 的响应中才会有意义。
582
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Location
583
- */
584
- Location?: string;
585
- /**
586
- *
587
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Max-Forwards
588
- */
589
- "Max-Forwards"?: string;
590
- /**
591
- *
592
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/NEL
593
- */
594
- NEL?: string;
595
- /**
596
- * 请求标头 Origin 表示了请求的来源(协议、主机、端口)。
597
- * 例如,如果一个用户代理需要请求一个页面中包含的资源,或者执行脚本中的 HTTP 请求(fetch),那么该页面的来源(origin)就可能被包含在这次请求中。
598
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Origin
599
- */
600
- Origin?: string;
601
- /**
602
- *
603
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Origin-Agent-Cluster
604
- */
605
- "Origin-Agent-Cluster"?: string;
606
- /**
607
- *
608
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Permissions-Policy
609
- */
610
- "Permissions-Policy"?: string;
611
- /**
612
- *
613
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Pragma
614
- * @deprecated
615
- */
616
- Pragma?: string;
617
- /**
618
- * The HTTP Proxy-Authenticate 是一个响应首部,指定了获取 proxy server(代理服务器)上的资源访问权限而采用的身份验证方式。
619
- * 代理服务器对请求进行验证,以便它进一步传递请求。
620
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Proxy-Authenticate
621
- */
622
- "Proxy-Authenticate"?: string;
623
- /**
624
- * Proxy-Authorization 是一个请求首部,其中包含了用户代理提供给代理服务器的用于身份验证的凭证。
625
- * 这个首部通常是在服务器返回了 407 Proxy Authentication Required 响应状态码及 Proxy-Authenticate 首部后发送的。
626
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Proxy-Authorization
627
- */
628
- "Proxy-Authorization"?: string;
629
- /**
630
- * The Range 是一个请求首部,告知服务器返回文件的哪一部分。在一个 Range 首部中,可以一次性请求多个部分,服务器会以 multipart 文件的形式将其返回。
631
- * 如果服务器返回的是范围响应,需要使用 206 Partial Content 状态码。
632
- * 假如所请求的范围不合法,那么服务器会返回 416 Range Not Satisfiable 状态码,表示客户端错误。
633
- * 服务器允许忽略 Range 首部,从而返回整个文件,状态码用 200 。
634
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Range
635
- */
636
- Range?: string;
637
- /**
638
- * Referer 请求头包含了当前请求页面的来源页面的地址,即表示当前页面是通过此来源页面里的链接进入的。
639
- * 服务端一般使用 Referer 请求头识别访问来源,可能会以此进行统计分析、日志记录以及缓存优化等。
640
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Referer
641
- */
642
- Referer?: string;
643
- /**
644
- * Referrer-Policy 首部用来监管哪些访问来源信息——会在 Referer 中发送——应该被包含在生成的请求当中
645
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Referrer-Policy
646
- */
647
- "Referrer-Policy"?:
648
- | "no-referrer"
649
- | "no-referrer-when-downgrade"
650
- | "origin"
651
- | "origin-when-cross-origin"
652
- | "same-origin"
653
- | "strict-origin"
654
- | "strict-origin-when-cross-origin"
655
- | "unsafe-url";
656
- /**
657
- * 在 HTTP 协议中,响应首部 Retry-After 表示用户代理需要等待多长时间之后才能继续发送请求。这个首部主要应用于以下两种场景:
658
- * + 当与 503 (Service Unavailable,当前服务不存在) 响应一起发送的时候,表示服务下线的预期时长。
659
- * + 当与重定向响应一起发送的时候,比如 301 (Moved Permanently,永久迁移),表示用户代理在发送重定向请求之前需要等待的最短时间。
660
- *
661
- *
662
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Retry-After
663
- */
664
- "Retry-After"?: string;
665
- /**
666
- *
667
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/RTT
668
- * @deprecated
669
- */
670
- RTT?: string;
671
- /**
672
- *
673
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Save-Data
674
- * @deprecated
675
- */
676
- "Save-Data"?: string;
677
- /**
678
- *
679
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-Prefers-Color-Scheme
680
- * @deprecated
681
- */
682
- "Sec-CH-Prefers-Color-Scheme"?: string;
683
- /**
684
- *
685
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-Prefers-Reduced-Motion
686
- * @deprecated
687
- */
688
- "Sec-CH-Prefers-Reduced-Motion"?: string;
689
- /**
690
- *
691
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-Prefers-Reduced-Transparency
692
- * @deprecated
693
- */
694
- "Sec-CH-Prefers-Reduced-Transparency"?: string;
695
- /**
696
- *
697
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA
698
- * @deprecated
699
- */
700
- "Sec-CH-UA"?: string;
701
- /**
702
- *
703
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA-Arch
704
- * @deprecated
705
- */
706
- "Sec-CH-UA-Arch"?: string;
707
- /**
708
- *
709
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA-Bitness
710
- * @deprecated
711
- */
712
- "Sec-CH-UA-Bitness"?: string;
713
- /**
714
- *
715
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA-Full-Version
716
- * @deprecated
717
- */
718
- "Sec-CH-UA-Full-Version"?: string;
719
- /**
720
- *
721
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA-Full-Version-List
722
- * @deprecated
723
- */
724
- "Sec-CH-UA-Full-Version-List"?: string;
725
- /**
726
- *
727
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA-Mobile
728
- * @deprecated
729
- */
730
- "Sec-CH-UA-Mobile"?: string;
731
- /**
732
- *
733
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA-Model
734
- * @deprecated
735
- */
736
- "Sec-CH-UA-Model"?: string;
737
- /**
738
- *
739
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA-Platform
740
- * @deprecated
741
- */
742
- "Sec-CH-UA-Platform"?: string;
743
- /**
744
- *
745
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-CH-UA-Platform-Version
746
- * @deprecated
747
- */
748
- "Sec-CH-UA-Platform-Version"?: string;
749
- /**
750
- * Sec-Fetch-Dest Fetch 元数据请求标头指示请求的目标,即数据的来源以及如何使用这些获取到的数据。
751
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-Fetch-Dest
752
- */
753
- "Sec-Fetch-Dest"?: string;
754
- /**
755
- * Sec-Fetch-Mode 获取元数据标头表明了一个请求的模式。
756
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-Fetch-Mode
757
- */
758
- "Sec-Fetch-Mode"?: string;
759
- /**
760
- * Sec-Fetch-Site 获取元数据标头表明了一个请求发起者的来源与目标资源来源之间的关系。
761
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-Fetch-Site
762
- */
763
- "Sec-Fetch-Site"?: string;
764
- /**
765
- * Sec-Fetch-User 获取元数据标头表明了一个导航请求是否由用户激活触发。
766
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-Fetch-User
767
- */
768
- "Sec-Fetch-User"?: string;
769
- /**
770
- *
771
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-GPC
772
- * @deprecated
773
- */
774
- "Sec-GPC"?: string;
775
- /**
776
- *
777
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-Purpose
778
- */
779
- "Sec-Purpose"?: string;
780
- /**
781
- * Sec-WebSocket-Accept 头(header)用在 websocket 开放握手中。它会出现在响应头中。
782
- * 也就是说,这是由服务器发送到客户端的头(header),用以告知服务器愿发起一个 websocket 连接。
783
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Sec-WebSocket-Accept
784
- */
785
- "Sec-WebSocket-Accept"?: string;
786
- /**
787
- * Server 首部包含了处理请求的源头服务器所用到的软件相关信息。
788
- *
789
- * 应该避免使用过长或者过于详细的描述作为 Server 的值,因为这有可能泄露服务器的内部实现细节,有利于攻击者找到或者探测已知的安全漏洞。
790
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Server
791
- */
792
- Server?: string;
793
- /**
794
- * Server-Timing 标头传达在一个给定请求 - 响应周期中的一个或多个参数和描述。
795
- * 它用于在用户浏览器的开发工具或 PerformanceServerTiming (en-US) 接口中显示任何后端服务器定时参数(例如,数据库读/写、CPU 时间、文件系统访问等)。
796
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Server-Timing
797
- */
798
- "Server-Timing"?: string;
799
- /**
800
- *
801
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Service-Worker-Navigation-Preload
802
- */
803
- "Service-Worker-Navigation-Preload"?: string;
804
- /**
805
- * Set-Cookie HTTP 响应标头用于将 cookie 由服务器发送到用户代理,以便用户代理在后续的请求中可以将其发送回服务器。
806
- * 要发送多个 cookie,则应在同一响应中发送多个 Set-Cookie 标头。
807
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Set-Cookie
808
- */
809
- "Set-Cookie"?: string;
810
- /**
811
- * SourceMap HTTP 响应头链接生成的代码到一个 source map,使浏览器能够重建原始的资源然后显示在调试器里。
812
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/SourceMap
813
- */
814
- SourceMap?: string;
815
- /**
816
- * HTTP Strict-Transport-Security(通常简称为 HSTS)响应标头用来通知浏览器应该只通过 HTTPS 访问该站点,并且以后使用 HTTP 访问该站点的所有尝试都应自动重定向到 HTTPS。
817
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Strict-Transport-Security
818
- */
819
- "Strict-Transport-Security"?: string;
820
- /**
821
- *
822
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Supports-Loading-Mode
823
- * @deprecated
824
- */
825
- "Supports-Loading-Mode"?: string;
826
- /**
827
- * TE 请求型头部用来指定用户代理希望使用的传输编码类型。(可以将其非正式称为 Accept-Transfer-Encoding,这个名称显得更直观一些)。
828
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/TE
829
- */
830
- TE?: string;
831
- /**
832
- * 响应头 Timing-Allow-Origin 用于指定特定站点,以允许其访问Resource Timing API提供的相关信息,否则这些信息会由于跨源限制将被报告为零
833
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Timing-Allow-Origin
834
- */
835
- "Timing-Allow-Origin"?: string;
836
- /**
837
- * Tk 响应首部显示了对相应请求的跟踪情况。
838
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Tk
839
- */
840
- Tk?: "!" | "?" | "G" | "N" | "T" | "C" | "P" | "D" | "U";
841
- /**
842
- * Trailer 是一个响应首部,允许发送方在分块发送的消息后面添加额外的元信息,这些元信息可能是随着消息主体的发送动态生成的,比如消息的完整性校验,消息的数字签名,或者消息经过处理之后的最终状态等。
843
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Trailer
844
- */
845
- Trailer?: string;
846
- /**
847
- * Transfer-Encoding 消息首部指明了将 entity 安全传递给用户所采用的编码形式。
848
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Transfer-Encoding
849
- */
850
- "Transfer-Encoding"?: string;
851
- /**
852
- *
853
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Upgrade
854
- */
855
- Upgrade?: string;
856
- /**
857
- * Upgrade-Insecure-Requests 是一个请求首部,用来向服务器端发送信号,表示客户端优先选择加密及带有身份验证的响应,并且它可以成功处理 upgrade-insecure-requests CSP (en-US) 指令。
858
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Upgrade-Insecure-Requests
859
- */
860
- "Upgrade-Insecure-Requests"?: string;
861
- /**
862
- * User-Agent 首部包含了一个特征字符串,用来让网络协议的对端来识别发起请求的用户代理软件的应用类型、操作系统、软件开发商以及版本号。
863
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/User-Agent
864
- */
865
- "User-Agent"?: string;
866
- /**
867
- * Vary HTTP 响应标头描述了除方法和 URL 之外影响响应内容的请求消息。大多数情况下,这用于在使用内容协商时创建缓存键。
868
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Vary
869
- */
870
- Vary?: string;
871
- /**
872
- * Via 是一个通用首部,是由代理服务器添加的,适用于正向和反向代理,在请求和响应首部中均可出现。
873
- * 这个消息首部可以用来追踪消息转发情况,防止循环请求,以及识别在请求或响应传递链中消息发送者对于协议的支持能力。
874
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Via
875
- */
876
- Via?: string;
877
- /**
878
- *
879
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Viewport-Width
880
- * @deprecated
881
- */
882
- "Viewport-Width"?: string;
883
- /**
884
- *
885
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Want-Digest
886
- * @deprecated
887
- */
888
- "Want-Digest"?: string;
889
- /**
890
- *
891
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Warning
892
- * @deprecated
893
- */
894
- Warning?: string;
895
- /**
896
- *
897
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Width
898
- * @deprecated
899
- */
900
- Width?: string;
901
- /**
902
- * HTTP WWW-Authenticate 响应标头定义了 HTTP 身份验证的方法(“质询”),它用于获取特定资源的访问权限。
903
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/WWW-Authenticate
904
- */
905
- "WWW-Authenticate"?: string;
906
- /**
907
- * X-Content-Type-Options HTTP 消息头相当于一个提示标志,被服务器用来提示客户端一定要遵循在 Content-Type 首部中对 MIME 类型 的设定,而不能对其进行修改。
908
- * 这就禁用了客户端的 MIME 类型嗅探行为,换句话说,也就是意味着网站管理员确定自己的设置没有问题。
909
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/X-Content-Type-Options
910
- */
911
- "X-Content-Type-Options"?: string;
912
- /**
913
- * X-Frame-Options HTTP 响应头是用来给浏览器指示允许一个页面可否在 <frame>、<iframe>、<embed> 或者 <object> 中展现的标记。
914
- * 站点可以通过确保网站没有被嵌入到别人的站点里面,从而避免点击劫持 (en-US)攻击。
915
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/X-Frame-Options
916
- */
917
- "X-Frame-Options"?: string;
918
- /**
919
- * HTTP X-XSS-Protection 响应头是 Internet Explorer,Chrome 和 Safari 的一个特性,当检测到跨站脚本攻击 (XSS (en-US)) 时,浏览器将停止加载页面。
920
- * 若网站设置了良好的 Content-Security-Policy 来禁用内联 JavaScript ('unsafe-inline'),现代浏览器不太需要这些保护,但其仍然可以为尚不支持 CSP 的旧版浏览器的用户提供保护。
921
- * + https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/X-XSS-Protection
922
- */
923
- "X-XSS-Protection"?: string;
924
- [key: string]: any;
925
- }
926
- export declare interface HttpxRequestInit extends RequestInit {
927
- /**
928
- * 请求的 body 信息:可能是一个 Blob、BufferSource、FormData、URLSearchParams 或者 USVString 对象。
929
- *
930
- * 注意 GET 或 HEAD 方法的请求不能包含 body 信息。
931
- */
932
- body?: BodyInit | null;
933
- /**
934
- * 请求的 cache 模式:default、 no-store、 reload 、 no-cache、 force-cache 或者 only-if-cached
935
- *
936
- * + 默认值: no-cache
937
- */
938
- cache?: RequestCache;
939
- /**
940
- * 请求的 credentials,如 omit、same-origin 或者 include。
941
- *
942
- * 为了在当前域名内自动发送 cookie,必须提供这个选项
943
- *
944
- * 从 Chrome 50 开始,这个属性也可以接受 FederatedCredential (en-US) 实例或是一个 PasswordCredential (en-US) 实例。
945
- *
946
- * + 默认值: include
947
- */
948
- credentials?: RequestCredentials;
949
- /**
950
- * 请求的头信息,形式为 Headers 的对象或包含 ByteString 值的对象字面量。
951
- */
952
- headers?: HeadersInit;
953
- /**
954
- * 包括请求的 subresource integrity 值(例如: sha256-BpfBw7ivV8q2jLiT13fxDYAe2tJllusRSZ273h2nFSE=)。
955
- */
956
- integrity?: string;
957
- /**
958
- * 保持连接
959
- */
960
- keepalive?: boolean;
961
- /**
962
- * 请求使用的方法,如 GET、POST。
963
- *
964
- * + 默认值: GET
965
- */
966
- method?: HttpxMethod;
967
- /**
968
- * 请求的模式,如 cors、no-cors 或者 same-origin。
969
- * + 默认值: cors
970
- */
971
- mode?: RequestMode;
972
- /**
973
- * 可用的 redirect 模式:follow (自动重定向), error (如果产生重定向将自动终止并且抛出一个错误),或者 manual (手动处理重定向)。
974
- *
975
- * 在 Chrome 中默认使用 follow(Chrome 47 之前的默认值是 manual)。
976
- *
977
- * + 默认值: follow
978
- */
979
- redirect?: RequestRedirect;
980
- /**
981
- * 一个 USVString 可以是 no-referrer、client 或一个 URL。默认是 client。
982
- */
983
- referrer?: "no-referrer" | "client" | string;
984
- /**
985
- * 指定了 HTTP 头部 referer 字段的值。
986
- *
987
- * 可能为以下值之一:no-referrer、 no-referrer-when-downgrade、origin、origin-when-cross-origin、 unsafe-url。
988
- *
989
- * + 默认值: origin-when-cross-origin
990
- */
991
- referrerPolicy?: ReferrerPolicy;
992
- /**
993
- * 用于设置请求信号的中止信号。
994
- *
995
- * + 默认值: 自己设置的signal中止信号
996
- */
997
- signal?: AbortSignal | null;
998
- /**
999
- * 只能为空。用于解除与任何窗口的请求的关联。
1000
- */
1001
- window?: null;
1002
- }
1003
- /** 允许拦截配置 */
1004
- export declare interface HttpxAllowInterceptConfig {
1005
- /** 允许 beforeRequest */
1006
- beforeRequest: boolean;
1007
- /** 允许 afterResponse 的success回调 */
1008
- afterResponseSuccess: boolean;
1009
- /** 允许 afterResponse 的error回调 */
1010
- afterResponseError: boolean;
1011
- }
1012
- /**
1013
- * 请求的配置
1014
- */
1015
- export declare interface HttpxDetails {
1016
- /**
1017
- * 网址
1018
- */
1019
- url?: string;
1020
- /**
1021
- * 请求方法
1022
- */
1023
- method?: HttpxMethod;
1024
- /**
1025
- * 超时时间,默认5000,可为空
1026
- *
1027
- * 当fetch为true时,该值不生效
1028
- */
1029
- timeout?: number;
1030
- /**
1031
- * 响应类型,默认document,可为空
1032
- */
1033
- responseType?: keyof HttpxResponseMap;
1034
- /**
1035
- * 请求头,可为空
1036
- */
1037
- headers?: HttpxHeaders;
1038
- /**
1039
- * 当使用post时,该值会生效,可为空
1040
- */
1041
- data?: string | FormData;
1042
- /**
1043
- * 当触发重定向的使用规则,默认follow,可为空
1044
- */
1045
- redirect?: HttpxRedirect;
1046
- /**
1047
- * 自定义Cookie,可为空
1048
- */
1049
- cookie?: string;
1050
- /**
1051
- * TamperMonkey5.2+
1052
- *
1053
- * @link https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/WebExtensions/API/cookies#storage_partitioning
1054
- */
1055
- cookiePartition?: {
1056
- /**
1057
- * 设置顶级站点
1058
- *
1059
- * @example
1060
- * http://*.example.com/
1061
- *
1062
- * @example
1063
- * http://www.example.com/
1064
- *
1065
- * @example
1066
- * *://*.example.com/
1067
- */
1068
- topLevelSite?: string;
1069
- };
1070
- /**
1071
- * 以二进制模式发送数据字符串,可为空
1072
- */
1073
- binary?: HttpxBinary;
1074
- /**
1075
- * 是否缓存资源,默认true,可为空
1076
- */
1077
- nocache?: boolean;
1078
- /**
1079
- * 是否重新验证可能缓存的内容,默认true,可为空
1080
- */
1081
- revalidate?: boolean;
1082
- /**
1083
- * 将该对象添加到响应的属性中,可为空
1084
- */
1085
- context?: any;
1086
- /**
1087
- * 重写mimeType,可为空
1088
- */
1089
- overrideMimeType?: string;
1090
- /**
1091
- * 是否匿名不发送Cookie,默认为false,可为空
1092
- */
1093
- anonymous?: boolean;
1094
- /**
1095
- * 是否使用fetch来发送请求,默认为false,可为空
1096
- */
1097
- fetch?: boolean;
1098
- /**
1099
- * 使用fetch请求的配置
1100
- */
1101
- fetchInit?: HttpxRequestInit;
1102
- /**
1103
- * 拒绝拦截配置
1104
- * 如果设置了相关配置,那么intercept将不会生效
1105
- */
1106
- allowInterceptConfig?: Partial<HttpxAllowInterceptConfig> | boolean;
1107
- /**
1108
- * 身份验证的用户名
1109
- */
1110
- user?: string;
1111
- /**
1112
- * 身份验证的密码
1113
- */
1114
- password?: string;
1115
- /**
1116
- * (可选)当请求被取消或中断,触发该回调
1117
- */
1118
- onabort?: (response?: any) => void;
1119
- /**
1120
- * (可选)当请求异常,触发该回调,如404
1121
- */
1122
- onerror?: (...args: any[]) => void;
1123
- /**
1124
- * (可选)当请求超时,触发该回调
1125
- */
1126
- ontimeout?: (...args: any[]) => void;
1127
- /**
1128
- * (可选)当请求开始,触发该回调
1129
- */
1130
- onloadstart?: (...args: any[]) => void;
1131
- /**
1132
- * (可选)当请求成功时,触发该回调
1133
- */
1134
- onload?: (...args: any[]) => void;
1135
- /**
1136
- * (可选)当请求状态改变,触发该回调
1137
- *
1138
- * fetch为true时该回调不触发
1139
- */
1140
- onreadystatechange?: (...args: any[]) => void;
1141
- /**
1142
- * (可选)当请求上传文件进度改变,触发该回调
1143
- *
1144
- * fetch为true时该回调不触发
1145
- */
1146
- onprogress?: (...args: any[]) => void;
1147
- }
1148
- export declare interface HttpxDetailsConfig extends HttpxDetails {
1149
- /**
1150
- * (可选)是否输出请求配置
1151
- */
1152
- logDetails?: boolean;
1153
- }
1154
- /**
1155
- * 响应的数据的data
1156
- */
1157
- export declare interface HttpxAsyncResultData<T = HttpxDetails> {
1158
- /**
1159
- * 如果fetch为true,且返回的headers中的Content-Type存在text/event-stream或者是主动设置的responseType为stream
1160
- * 则存在该属性为true
1161
- */
1162
- isStream?: boolean;
1163
- /**
1164
- * 如果fetch为true,则存在该属性为true
1165
- */
1166
- isFetch?: boolean;
1167
- /**
1168
- * 当数据加载完毕后的,经过所有重定向后的最终URL
1169
- */
1170
- finalUrl: string;
1171
- /**
1172
- * 数据准备状态
1173
- * + 0 未初始化
1174
- * + 1 载入
1175
- * + 2 载入完成
1176
- * + 3 交互
1177
- * + 4 完成
1178
- *
1179
- * 当请求头fetch为true时,该值固定为4
1180
- */
1181
- readyState: 0 | 1 | 2 | 3 | 4;
1182
- /**
1183
- * 状态码,2xx为成功
1184
- */
1185
- status: HttpxStatus;
1186
- /**
1187
- * 关于status的解释
1188
- */
1189
- statusText: "OK" | "" | string;
1190
- /**
1191
- * 响应内容,根据responseType,如果是html,那就是Document类型,如果是json,那么类型是Object类型
1192
- */
1193
- response: HttpxResponseMap[keyof HttpxResponseMap];
1194
- /**
1195
- * 当请求头fetch为true时,该属性存在
1196
- */
1197
- responseFetchHeaders?: Headers;
1198
- /**
1199
- * 响应头的Headers
1200
- */
1201
- responseHeaders: string;
1202
- /**
1203
- * 响应的字符串
1204
- */
1205
- responseText: string;
1206
- /**
1207
- * 是请求中设置的responseType,没有设置的话默认为undefined
1208
- */
1209
- responseType?: keyof HttpxResponseMap;
1210
- /**
1211
- * the response data as XML document
1212
- */
1213
- responseXML?: XMLDocument;
1214
- }
1215
- /**
1216
- * 响应的数据
1217
- */
1218
- export declare interface HttpxAsyncResult<T = HttpxDetails> {
1219
- /**
1220
- * 请求状态,状态码为200为成功true,否则false
1221
- */
1222
- status: boolean;
1223
- /**
1224
- * 请求的数据,当status为false时,data中可能也存在数据
1225
- */
1226
- data: HttpxAsyncResultData<T>;
1227
- /**
1228
- * 请求的配置
1229
- */
1230
- details: T;
1231
- /**
1232
- * 请求的成功/失败消息
1233
- */
1234
- msg: string;
1235
- /**
1236
- * 当前触发响应的类型
1237
- */
1238
- type: HttpxResponseCallBackType;
1239
- }
1240
-
1241
- export declare interface HttpxHookErrorData {
1242
- type: "onerror" | "ontimeout" | "onabort";
1243
- error: Error;
1244
- response: any;
1245
- }
1246
-
1247
- export type HttpxPromise<T> = Promise<T> & {
1248
- /**
1249
- * 用于取消发送的请求,并执行resolve返回abort
1250
- */
1251
- abort(): void;
1252
- };
1253
-
1254
13
  class Httpx {
1255
14
  private GM_Api = {
1256
15
  xmlHttpRequest: null as any,
@@ -1273,7 +32,7 @@ class Httpx {
1273
32
  * @param details 当前的请求配置
1274
33
  * @private
1275
34
  */
1276
- beforeRequestCallBack(details: HttpxDetails) {
35
+ beforeRequestCallBack(details: HttpxRequestOption) {
1277
36
  if (typeof details.allowInterceptConfig === "boolean") {
1278
37
  if (!details.allowInterceptConfig) {
1279
38
  // 不允许拦截
@@ -1365,8 +124,8 @@ class Httpx {
1365
124
  * @param details 请求的配置
1366
125
  */
1367
126
  successResponseCallBack(
1368
- response: HttpxAsyncResultData,
1369
- details: HttpxDetails
127
+ response: HttpxResponseData<HttpxRequestOption>,
128
+ details: HttpxRequestOption
1370
129
  ) {
1371
130
  if (typeof details.allowInterceptConfig === "boolean") {
1372
131
  if (!details.allowInterceptConfig) {
@@ -1406,14 +165,9 @@ class Httpx {
1406
165
  * @returns
1407
166
  * 返回null|undefined就是拦截掉了
1408
167
  */
1409
- errorResponseCallBack<
1410
- T extends {
1411
- type: "onerror" | "ontimeout" | "onabort";
1412
- error: Error;
1413
- response: any;
1414
- details: HttpxDetails;
1415
- }
1416
- >(data: T): T | null | undefined {
168
+ errorResponseCallBack<T extends HttpxHookErrorData>(
169
+ data: T
170
+ ): T | null | undefined {
1417
171
  if (typeof data.details.allowInterceptConfig === "boolean") {
1418
172
  if (!data.details.allowInterceptConfig) {
1419
173
  // 不允许拦截
@@ -1486,65 +240,71 @@ class Httpx {
1486
240
  /**
1487
241
  * 根据传入的参数处理获取details配置
1488
242
  */
1489
- handleBeforeRequestDetails(...args: (HttpxDetails | string)[]) {
1490
- let result: HttpxDetails = {};
243
+ handleBeforeRequestOption(...args: (HttpxRequestOption | string)[]) {
244
+ let option: HttpxRequestOption = {};
1491
245
  if (typeof args[0] === "string") {
1492
246
  /* 传入的是url,details? */
1493
247
  let url = args[0];
1494
- result.url = url;
248
+ option.url = url;
1495
249
  if (typeof args[1] === "object") {
1496
250
  /* 处理第二个参数details */
1497
251
  let details = args[1];
1498
- result = details;
1499
- result.url = url;
252
+ option = details;
253
+ option.url = url;
1500
254
  }
1501
255
  } else {
1502
256
  /* 传入的是details */
1503
- result = args[0];
257
+ option = args[0];
1504
258
  }
1505
- return result;
259
+ return option;
1506
260
  },
1507
261
  /**
1508
262
  * 获取请求配置
1509
263
  * @param method 当前请求方法,默认get
1510
- * @param details 请求配置
264
+ * @param userRequestOption 用户的请求配置
1511
265
  * @param resolve promise回调
1512
266
  * @param reject 抛出错误回调
1513
267
  */
1514
- getDetails(
268
+ getRequestOption(
1515
269
  method: HttpxMethod,
1516
- details: HttpxDetails,
270
+ userRequestOption: HttpxRequestOption,
1517
271
  resolve: (...args: any[]) => void,
1518
272
  reject: (...args: any[]) => void
1519
273
  ) {
1520
274
  let that = this;
1521
- let result = <Required<HttpxDetails>>{
1522
- url: details.url || this.context.#defaultDetails.url,
275
+ let requestOption = <Required<HttpxRequestOption>>{
276
+ url: userRequestOption.url || this.context.#defaultDetails.url,
1523
277
  method: (method || "GET").toString().toUpperCase(),
1524
- timeout: details.timeout || this.context.#defaultDetails.timeout,
278
+ timeout:
279
+ userRequestOption.timeout || this.context.#defaultDetails.timeout,
1525
280
  responseType:
1526
- details.responseType || this.context.#defaultDetails.responseType,
281
+ userRequestOption.responseType ||
282
+ this.context.#defaultDetails.responseType,
1527
283
  /* 对象使用深拷贝 */
1528
284
  headers: Utils.deepClone(this.context.#defaultDetails.headers),
1529
- data: details.data || this.context.#defaultDetails.data,
1530
- redirect: details.redirect || this.context.#defaultDetails.redirect,
1531
- cookie: details.cookie || this.context.#defaultDetails.cookie,
285
+ data: userRequestOption.data || this.context.#defaultDetails.data,
286
+ redirect:
287
+ userRequestOption.redirect || this.context.#defaultDetails.redirect,
288
+ cookie: userRequestOption.cookie || this.context.#defaultDetails.cookie,
1532
289
  cookiePartition:
1533
- details.cookiePartition ||
290
+ userRequestOption.cookiePartition ||
1534
291
  this.context.#defaultDetails.cookiePartition,
1535
- binary: details.binary || this.context.#defaultDetails.binary,
1536
- nocache: details.nocache || this.context.#defaultDetails.nocache,
292
+ binary: userRequestOption.binary || this.context.#defaultDetails.binary,
293
+ nocache:
294
+ userRequestOption.nocache || this.context.#defaultDetails.nocache,
1537
295
  revalidate:
1538
- details.revalidate || this.context.#defaultDetails.revalidate,
296
+ userRequestOption.revalidate ||
297
+ this.context.#defaultDetails.revalidate,
1539
298
  /* 对象使用深拷贝 */
1540
299
  context: Utils.deepClone(
1541
- details.context || this.context.#defaultDetails.context
300
+ userRequestOption.context || this.context.#defaultDetails.context
1542
301
  ),
1543
302
  overrideMimeType:
1544
- details.overrideMimeType ||
303
+ userRequestOption.overrideMimeType ||
1545
304
  this.context.#defaultDetails.overrideMimeType,
1546
- anonymous: details.anonymous || this.context.#defaultDetails.anonymous,
1547
- fetch: details.fetch || this.context.#defaultDetails.fetch,
305
+ anonymous:
306
+ userRequestOption.anonymous || this.context.#defaultDetails.anonymous,
307
+ fetch: userRequestOption.fetch || this.context.#defaultDetails.fetch,
1548
308
  /* 对象使用深拷贝 */
1549
309
  fetchInit: Utils.deepClone(this.context.#defaultDetails.fetchInit),
1550
310
  allowInterceptConfig: {
@@ -1561,11 +321,12 @@ class Httpx {
1561
321
  .allowInterceptConfig as HttpxAllowInterceptConfig
1562
322
  ).afterResponseError,
1563
323
  },
1564
- user: details.user || this.context.#defaultDetails.user,
1565
- password: details.password || this.context.#defaultDetails.password,
324
+ user: userRequestOption.user || this.context.#defaultDetails.user,
325
+ password:
326
+ userRequestOption.password || this.context.#defaultDetails.password,
1566
327
  onabort(...args) {
1567
328
  that.context.HttpxCallBack.onAbort(
1568
- details as Required<HttpxDetails>,
329
+ userRequestOption as Required<HttpxRequestOption>,
1569
330
  resolve,
1570
331
  reject,
1571
332
  args
@@ -1573,7 +334,7 @@ class Httpx {
1573
334
  },
1574
335
  onerror(...args) {
1575
336
  that.context.HttpxCallBack.onError(
1576
- details as Required<HttpxDetails>,
337
+ userRequestOption as Required<HttpxRequestOption>,
1577
338
  resolve,
1578
339
  reject,
1579
340
  args
@@ -1581,25 +342,25 @@ class Httpx {
1581
342
  },
1582
343
  onloadstart(...args) {
1583
344
  that.context.HttpxCallBack.onLoadStart(
1584
- details as Required<HttpxDetails>,
345
+ userRequestOption as Required<HttpxRequestOption>,
1585
346
  args
1586
347
  );
1587
348
  },
1588
349
  onprogress(...args) {
1589
350
  that.context.HttpxCallBack.onProgress(
1590
- details as Required<HttpxDetails>,
351
+ userRequestOption as Required<HttpxRequestOption>,
1591
352
  args
1592
353
  );
1593
354
  },
1594
355
  onreadystatechange(...args) {
1595
356
  that.context.HttpxCallBack.onReadyStateChange(
1596
- details as Required<HttpxDetails>,
357
+ userRequestOption as Required<HttpxRequestOption>,
1597
358
  args
1598
359
  );
1599
360
  },
1600
361
  ontimeout(...args) {
1601
362
  that.context.HttpxCallBack.onTimeout(
1602
- details as Required<HttpxDetails>,
363
+ userRequestOption as Required<HttpxRequestOption>,
1603
364
  resolve,
1604
365
  reject,
1605
366
  args
@@ -1607,7 +368,7 @@ class Httpx {
1607
368
  },
1608
369
  onload(...args) {
1609
370
  that.context.HttpxCallBack.onLoad(
1610
- details as Required<HttpxDetails>,
371
+ userRequestOption as Required<HttpxRequestOption>,
1611
372
  resolve,
1612
373
  reject,
1613
374
  args
@@ -1615,46 +376,60 @@ class Httpx {
1615
376
  },
1616
377
  };
1617
378
  // 补全allowInterceptConfig参数
1618
- if (typeof details.allowInterceptConfig === "boolean") {
379
+ if (typeof userRequestOption.allowInterceptConfig === "boolean") {
1619
380
  Object.keys(
1620
- result.allowInterceptConfig as HttpxAllowInterceptConfig
381
+ requestOption.allowInterceptConfig as HttpxAllowInterceptConfig
1621
382
  ).forEach((keyName) => {
1622
- (result.allowInterceptConfig as any)[keyName] =
1623
- details.allowInterceptConfig;
383
+ Reflect.set(
384
+ requestOption.allowInterceptConfig as HttpxAllowInterceptConfig,
385
+ keyName,
386
+ userRequestOption.allowInterceptConfig
387
+ );
1624
388
  });
1625
389
  } else {
1626
390
  if (
1627
- typeof details.allowInterceptConfig === "object" &&
1628
- details.allowInterceptConfig != null
391
+ typeof userRequestOption.allowInterceptConfig === "object" &&
392
+ userRequestOption.allowInterceptConfig != null
1629
393
  ) {
1630
- Object.keys(details.allowInterceptConfig).forEach((keyName) => {
1631
- let value = (details.allowInterceptConfig as any)[
1632
- keyName
1633
- ] as boolean;
1634
- if (
1635
- keyName in
1636
- (result.allowInterceptConfig as HttpxAllowInterceptConfig) &&
1637
- typeof value === "boolean"
1638
- ) {
1639
- (result.allowInterceptConfig as any)[keyName] = value;
394
+ Object.keys(userRequestOption.allowInterceptConfig).forEach(
395
+ (keyName) => {
396
+ let value = Reflect.get(
397
+ userRequestOption.allowInterceptConfig as HttpxAllowInterceptConfig,
398
+ keyName
399
+ ) as Boolean;
400
+ if (
401
+ typeof value === "boolean" &&
402
+ Reflect.has(
403
+ requestOption.allowInterceptConfig as HttpxAllowInterceptConfig,
404
+ keyName
405
+ )
406
+ ) {
407
+ Reflect.set(
408
+ requestOption.allowInterceptConfig as HttpxAllowInterceptConfig,
409
+ keyName,
410
+ value
411
+ );
412
+ }
1640
413
  }
1641
- });
414
+ );
1642
415
  }
1643
416
  }
1644
417
  if (typeof this.context.GM_Api.xmlHttpRequest !== "function") {
1645
- result.fetch = true;
418
+ // GM函数不存在,强制使用fetch
419
+ requestOption.fetch = true;
1646
420
  }
1647
- if (typeof result.headers === "object") {
1648
- if (typeof details.headers === "object") {
1649
- Object.keys(details.headers).forEach((keyName, index) => {
421
+ if (typeof requestOption.headers === "object") {
422
+ if (typeof userRequestOption.headers === "object") {
423
+ Object.keys(userRequestOption.headers).forEach((keyName, index) => {
1650
424
  if (
1651
- keyName in result.headers &&
1652
- details!.headers?.[keyName] == null
425
+ keyName in requestOption.headers &&
426
+ userRequestOption!.headers?.[keyName] == null
1653
427
  ) {
1654
428
  /* 在默认的header中存在,且设置它新的值为空,那么就是默认的值 */
1655
- Reflect.deleteProperty(result.headers, keyName);
429
+ Reflect.deleteProperty(requestOption.headers, keyName);
1656
430
  } else {
1657
- result.headers[keyName] = details?.headers?.[keyName];
431
+ requestOption.headers[keyName] =
432
+ userRequestOption?.headers?.[keyName];
1658
433
  }
1659
434
  });
1660
435
  } else {
@@ -1662,99 +437,195 @@ class Httpx {
1662
437
  /* 不做处理 */
1663
438
  }
1664
439
  } else {
1665
- (result as HttpxDetails).headers = details.headers;
440
+ /* 默认的headers不是对象,那么就直接使用新的 */
441
+ Reflect.set(requestOption, "headers", userRequestOption.headers);
1666
442
  }
1667
- if (typeof result.fetchInit === "object") {
443
+ if (typeof requestOption.fetchInit === "object") {
1668
444
  /* 使用assign替换且添加 */
1669
- if (typeof details.fetchInit === "object") {
1670
- Object.keys(details.fetchInit).forEach((keyName, index) => {
445
+ if (typeof userRequestOption.fetchInit === "object") {
446
+ Object.keys(userRequestOption.fetchInit).forEach((keyName, index) => {
1671
447
  if (
1672
- keyName in result.fetchInit &&
1673
- (details as any).fetchInit[keyName] == null
448
+ keyName in requestOption.fetchInit &&
449
+ (userRequestOption as any).fetchInit[keyName] == null
1674
450
  ) {
1675
451
  /* 在默认的fetchInit中存在,且设置它新的值为空,那么就是默认的值 */
1676
- Reflect.deleteProperty(result.fetchInit, keyName);
452
+ Reflect.deleteProperty(requestOption.fetchInit, keyName);
1677
453
  } else {
1678
- (result as any).fetchInit[keyName] = (details as any).fetchInit[
1679
- keyName
1680
- ];
454
+ Reflect.set(
455
+ requestOption.fetchInit,
456
+ keyName,
457
+ Reflect.get(userRequestOption.fetchInit!, keyName)
458
+ );
1681
459
  }
1682
460
  });
1683
461
  }
1684
462
  } else {
1685
- (result as any).fetchInit = details.fetchInit;
463
+ Reflect.set(requestOption, "fetchInit", userRequestOption.fetchInit);
1686
464
  }
1687
465
 
1688
466
  // 处理新的cookiePartition
1689
467
  if (
1690
- typeof result.cookiePartition === "object" &&
1691
- result.cookiePartition != null
468
+ typeof requestOption.cookiePartition === "object" &&
469
+ requestOption.cookiePartition != null
1692
470
  ) {
1693
471
  if (
1694
- Reflect.has(result.cookiePartition, "topLevelSite") &&
1695
- typeof result.cookiePartition.topLevelSite !== "string"
472
+ Reflect.has(requestOption.cookiePartition, "topLevelSite") &&
473
+ typeof requestOption.cookiePartition.topLevelSite !== "string"
1696
474
  ) {
1697
475
  // topLevelSite必须是字符串
1698
- Reflect.deleteProperty(result.cookiePartition, "topLevelSite");
476
+ Reflect.deleteProperty(requestOption.cookiePartition, "topLevelSite");
477
+ }
478
+ }
479
+
480
+ /* 完善请求的url */
481
+ try {
482
+ new URL(requestOption.url);
483
+ } catch (error) {
484
+ if (requestOption.url.startsWith("//")) {
485
+ // 补充https:
486
+ requestOption.url = globalThis.location.protocol + requestOption.url;
487
+ } else if (requestOption.url.startsWith("/")) {
488
+ // 补充origin
489
+ requestOption.url = globalThis.location.origin + requestOption.url;
490
+ } else {
491
+ // 补充origin+/
492
+ requestOption.url =
493
+ globalThis.location.origin + "/" + requestOption.url;
494
+ }
495
+ }
496
+
497
+ if (requestOption.fetchInit && !requestOption.fetch) {
498
+ // 清空fetchInit
499
+ Reflect.deleteProperty(requestOption, "fetchInit");
500
+ }
501
+
502
+ // 转换data类型
503
+ try {
504
+ /** 是否对数据进行处理 */
505
+ let processData = userRequestOption.processData ?? true;
506
+ if (requestOption.data != null && processData) {
507
+ let method = requestOption.method;
508
+ if (method === "GET" || method === "HEAD") {
509
+ // GET类型,data如果有,那么需要转为searchParams
510
+ let urlObj = new URL(requestOption.url);
511
+ let urlSearch = "";
512
+ if (typeof requestOption.data === "string") {
513
+ urlSearch = requestOption.data;
514
+ } else if (typeof requestOption.data === "object") {
515
+ // URLSearchParams参数可以转普通的string:string,包括FormData
516
+ // @ts-ignore
517
+ let searchParams = new URLSearchParams(requestOption.data);
518
+ urlSearch = searchParams.toString();
519
+ }
520
+ if (urlSearch != "") {
521
+ if (urlObj.search === "") {
522
+ // url没有search参数,直接覆盖
523
+ urlObj.search = urlSearch;
524
+ } else {
525
+ // 有search参数
526
+ if (urlObj.search.endsWith("&")) {
527
+ // xxx=xxx&
528
+ urlObj.search = urlObj.search + urlSearch;
529
+ } else {
530
+ // xxx=xxx&xxx=
531
+ urlObj.search = urlObj.search + "&" + urlSearch;
532
+ }
533
+ }
534
+ }
535
+ requestOption.url = urlObj.toString();
536
+ } else if (method === "POST" && requestOption.headers != null) {
537
+ // POST类型,data如果是FormData,那么需要转为string
538
+ let headersKeyList = Object.keys(requestOption.headers);
539
+ let ContentTypeIndex = headersKeyList.findIndex((headerKey) => {
540
+ return (
541
+ headerKey.trim().toLowerCase() === "content-type" &&
542
+ typeof requestOption.headers[headerKey] === "string"
543
+ );
544
+ });
545
+ if (ContentTypeIndex !== -1) {
546
+ let ContentTypeKey = headersKeyList[ContentTypeIndex];
547
+ // 设置了Content-Type
548
+ let ContentType = requestOption.headers[
549
+ ContentTypeIndex
550
+ ].toLowerCase() as string;
551
+ if (ContentType.includes("application/json")) {
552
+ // application/json
553
+ if (requestOption.data instanceof FormData) {
554
+ const entries: { [key: string]: any } = {};
555
+ requestOption.data.forEach((value, key) => {
556
+ entries[key] = value;
557
+ });
558
+ requestOption.data = JSON.stringify(entries);
559
+ } else if (typeof requestOption.data === "object") {
560
+ requestOption.data = JSON.stringify(requestOption.data);
561
+ }
562
+ } else if (
563
+ ContentType.includes("application/x-www-form-urlencoded")
564
+ ) {
565
+ // application/x-www-form-urlencoded
566
+ if (typeof requestOption.data === "object") {
567
+ requestOption.data = new URLSearchParams(
568
+ // @ts-ignore
569
+ requestOption.data
570
+ ).toString();
571
+ }
572
+ } else if (ContentType.includes("multipart/form-data")) {
573
+ // multipart/form-data
574
+ if (requestOption.data instanceof FormData) {
575
+ Reflect.deleteProperty(requestOption.headers, ContentTypeKey);
576
+ }
577
+ }
578
+ }
579
+ }
1699
580
  }
581
+ } catch (error) {
582
+ console.warn("Httpx ==> 转换data参数错误", error);
1700
583
  }
1701
- return result;
584
+ return requestOption;
1702
585
  },
1703
586
  /**
1704
- * 处理发送请求的details,去除值为undefined、空function的值
1705
- * @param details
587
+ * 处理发送请求的配置,去除值为undefined、空function的值
588
+ * @param option
1706
589
  */
1707
- handle(details: Required<HttpxDetails>): HttpxDetails {
1708
- Object.keys(details).forEach((keyName) => {
590
+ removeRequestNullOption(
591
+ option: Required<HttpxRequestOption>
592
+ ): HttpxRequestOption {
593
+ Object.keys(option).forEach((keyName) => {
1709
594
  if (
1710
- details[keyName as keyof HttpxDetails] == null ||
1711
- (details[keyName as keyof HttpxDetails] instanceof Function &&
1712
- Utils.isNull(details[keyName as keyof HttpxDetails]))
595
+ option[keyName as keyof HttpxRequestOption] == null ||
596
+ (option[keyName as keyof HttpxRequestOption] instanceof Function &&
597
+ Utils.isNull(option[keyName as keyof HttpxRequestOption]))
1713
598
  ) {
1714
- Reflect.deleteProperty(details, keyName);
599
+ Reflect.deleteProperty(option, keyName);
1715
600
  return;
1716
601
  }
1717
602
  });
1718
- if (Utils.isNull(details.url)) {
1719
- throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${details.url}`);
1720
- }
1721
- /* method值统一大写,兼容Via */
1722
- (details as any).method = details.method.toUpperCase();
1723
- /* 判断是否是以http开头,否则主动加上origin */
1724
- try {
1725
- new URL(details.url);
1726
- } catch (error) {
1727
- if (details.url.startsWith("//")) {
1728
- details.url = window.location.protocol + details.url;
1729
- } else if (details.url.startsWith("/")) {
1730
- details.url = window.location.origin + details.url;
1731
- } else {
1732
- details.url = window.location.origin + "/" + details.url;
1733
- }
603
+ if (Utils.isNull(option.url)) {
604
+ throw new TypeError(`Utils.Httpx 参数 url不符合要求: ${option.url}`);
1734
605
  }
1735
- return details;
606
+ return option;
1736
607
  },
1737
608
  /**
1738
609
  * 处理fetch的配置
1739
- * @param details
610
+ * @param option
1740
611
  */
1741
- handleFetchDetail(details: Required<HttpxDetails>) {
612
+ handleFetchOption(option: Required<HttpxRequestOption>) {
1742
613
  /**
1743
614
  * fetch的请求配置
1744
615
  **/
1745
- let fetchRequestInit = <RequestInit>{};
616
+ let fetchRequestOption = <RequestInit>{};
1746
617
  if (
1747
- (details.method === "GET" || details.method === "HEAD") &&
1748
- details.data != null
618
+ (option.method === "GET" || option.method === "HEAD") &&
619
+ option.data != null
1749
620
  ) {
1750
621
  /* GET 或 HEAD 方法的请求不能包含 body 信息 */
1751
- Reflect.deleteProperty(details, "data");
622
+ Reflect.deleteProperty(option, "data");
1752
623
  }
1753
624
  /* 中止信号控制器 */
1754
625
  let abortController = new AbortController();
1755
626
  let signal = abortController.signal;
1756
627
  signal.onabort = () => {
1757
- details.onabort({
628
+ option.onabort({
1758
629
  isFetch: true,
1759
630
  responseText: "",
1760
631
  response: null,
@@ -1765,19 +636,28 @@ class Httpx {
1765
636
  error: "aborted",
1766
637
  });
1767
638
  };
1768
- fetchRequestInit.method = details.method ?? "GET";
1769
- fetchRequestInit.headers = details.headers;
1770
- fetchRequestInit.body = details.data;
1771
- fetchRequestInit.mode = "cors";
1772
- fetchRequestInit.credentials = "include";
1773
- fetchRequestInit.cache = "no-cache";
1774
- fetchRequestInit.redirect = "follow";
1775
- fetchRequestInit.referrerPolicy = "origin-when-cross-origin";
1776
- fetchRequestInit.signal = signal;
1777
- Object.assign(fetchRequestInit, details.fetchInit || {});
639
+ // 设置请求
640
+ fetchRequestOption.method = option.method ?? "GET";
641
+ // 设置请求头
642
+ fetchRequestOption.headers = option.headers;
643
+ // 设置请求体
644
+ fetchRequestOption.body = option.data as string | FormData;
645
+ // 设置跨域
646
+ fetchRequestOption.mode = "cors";
647
+ // 设置包含
648
+ fetchRequestOption.credentials = "include";
649
+ // 设置不缓存
650
+ fetchRequestOption.cache = "no-cache";
651
+ // 设置始终重定向
652
+ fetchRequestOption.redirect = "follow";
653
+ // 设置referer跨域
654
+ fetchRequestOption.referrerPolicy = "origin-when-cross-origin";
655
+ // 设置信号中断
656
+ fetchRequestOption.signal = signal;
657
+ Object.assign(fetchRequestOption, option.fetchInit || {});
1778
658
  return {
1779
- fetchDetails: details,
1780
- fetchRequestInit: fetchRequestInit,
659
+ fetchOption: option,
660
+ fetchRequestOption: fetchRequestOption,
1781
661
  abortController: abortController,
1782
662
  };
1783
663
  },
@@ -1789,18 +669,23 @@ class Httpx {
1789
669
  * @param details 配置
1790
670
  * @param resolve 回调
1791
671
  * @param reject 抛出错误
1792
- * @param argumentsList 参数列表
672
+ * @param argsResult 返回的参数列表
1793
673
  */
1794
674
  onAbort(
1795
- details: Required<HttpxDetails>,
1796
- resolve: (...rags: any[]) => void,
675
+ details: Required<HttpxRequestOption>,
676
+ resolve: (resultOption: HttpxResponse<HttpxRequestOption>) => void,
1797
677
  reject: (...args: any[]) => void,
1798
- argumentsList: any
678
+ argsResult: any
1799
679
  ) {
680
+ // console.log(argsResult);
1800
681
  if ("onabort" in details) {
1801
- details.onabort.apply(this, argumentsList);
682
+ details.onabort.apply(this, argsResult);
1802
683
  } else if ("onabort" in this.context.#defaultDetails) {
1803
- this.context.#defaultDetails!.onabort!.apply(this, argumentsList);
684
+ this.context.#defaultDetails!.onabort!.apply(this, argsResult);
685
+ }
686
+ let response = argsResult;
687
+ if (response.length) {
688
+ response = response[0];
1804
689
  }
1805
690
  if (
1806
691
  this.context.HttpxResponseHook.errorResponseCallBack({
@@ -1814,9 +699,11 @@ class Httpx {
1814
699
  return;
1815
700
  }
1816
701
  resolve({
1817
- status: false,
1818
- data: [...argumentsList],
702
+ data: response,
703
+ details: details,
1819
704
  msg: "请求被取消",
705
+ status: false,
706
+ statusCode: -1,
1820
707
  type: "onabort",
1821
708
  });
1822
709
  },
@@ -1826,20 +713,21 @@ class Httpx {
1826
713
  * @param details 配置
1827
714
  * @param resolve 回调
1828
715
  * @param reject 抛出错误
1829
- * @param argumentsList 响应的参数列表
716
+ * @param argsResult 返回的参数列表
1830
717
  */
1831
718
  onError(
1832
- details: Required<HttpxDetails>,
1833
- resolve: (...args: any[]) => void,
719
+ details: Required<HttpxRequestOption>,
720
+ resolve: (resultOption: HttpxResponse<HttpxRequestOption>) => void,
1834
721
  reject: (...args: any[]) => void,
1835
- argumentsList: any
722
+ argsResult: any
1836
723
  ) {
724
+ // console.log(argsResult);
1837
725
  if ("onerror" in details) {
1838
- details.onerror.apply(this, argumentsList);
726
+ details.onerror.apply(this, argsResult);
1839
727
  } else if ("onerror" in this.context.#defaultDetails) {
1840
- this.context.#defaultDetails!.onerror!.apply(this, argumentsList);
728
+ this.context.#defaultDetails!.onerror!.apply(this, argsResult);
1841
729
  }
1842
- let response = argumentsList;
730
+ let response = argsResult;
1843
731
  if (response.length) {
1844
732
  response = response[0];
1845
733
  }
@@ -1855,10 +743,11 @@ class Httpx {
1855
743
  return;
1856
744
  }
1857
745
  resolve({
1858
- status: false,
1859
746
  data: response,
1860
747
  details: details,
1861
748
  msg: "请求异常",
749
+ status: false,
750
+ statusCode: response["status"],
1862
751
  type: "onerror",
1863
752
  });
1864
753
  },
@@ -1867,25 +756,29 @@ class Httpx {
1867
756
  * @param details 配置
1868
757
  * @param resolve 回调
1869
758
  * @param reject 抛出错误
1870
- * @param argumentsList 参数列表
759
+ * @param argsResult 返回的参数列表
1871
760
  */
1872
761
  onTimeout(
1873
- details: Required<HttpxDetails>,
1874
- resolve: (...args: any[]) => void,
762
+ details: Required<HttpxRequestOption>,
763
+ resolve: (resultOption: HttpxResponse<HttpxRequestOption>) => void,
1875
764
  reject: (...args: any[]) => void,
1876
- argumentsList: any
765
+ argsResult: any
1877
766
  ) {
767
+ // console.log(argsResult);
1878
768
  if ("ontimeout" in details) {
1879
- details.ontimeout.apply(this, argumentsList);
769
+ details.ontimeout.apply(this, argsResult);
1880
770
  } else if ("ontimeout" in this.context.#defaultDetails) {
1881
- this.context.#defaultDetails!.ontimeout!.apply(this, argumentsList);
771
+ this.context.#defaultDetails!.ontimeout!.apply(this, argsResult);
772
+ }
773
+ let response = argsResult;
774
+ if (response.length) {
775
+ response = response[0];
1882
776
  }
1883
-
1884
777
  if (
1885
778
  this.context.HttpxResponseHook.errorResponseCallBack({
1886
779
  type: "ontimeout",
1887
780
  error: new TypeError("request timeout"),
1888
- response: (argumentsList || [null])[0],
781
+ response: (argsResult || [null])[0],
1889
782
  details: details,
1890
783
  }) == null
1891
784
  ) {
@@ -1893,9 +786,11 @@ class Httpx {
1893
786
  return;
1894
787
  }
1895
788
  resolve({
1896
- status: false,
1897
- data: [...argumentsList],
789
+ data: response,
790
+ details: details,
1898
791
  msg: "请求超时",
792
+ status: false,
793
+ statusCode: 0,
1899
794
  type: "ontimeout",
1900
795
  });
1901
796
  },
@@ -1903,13 +798,14 @@ class Httpx {
1903
798
  /**
1904
799
  * onloadstart请求开始-触发
1905
800
  * @param details 配置
1906
- * @param argumentsList 参数列表
801
+ * @param argsResult 返回的参数列表
1907
802
  */
1908
- onLoadStart(details: Required<HttpxDetails>, argumentsList: any) {
803
+ onLoadStart(details: Required<HttpxRequestOption>, argsResult: any[]) {
804
+ // console.log(argsResult);
1909
805
  if ("onloadstart" in details) {
1910
- details.onloadstart.apply(this, argumentsList);
806
+ details.onloadstart.apply(this, argsResult);
1911
807
  } else if ("onloadstart" in this.context.#defaultDetails) {
1912
- this.context.#defaultDetails!.onloadstart!.apply(this, argumentsList);
808
+ this.context.#defaultDetails!.onloadstart!.apply(this, argsResult);
1913
809
  }
1914
810
  },
1915
811
  /**
@@ -1917,16 +813,17 @@ class Httpx {
1917
813
  * @param details 请求的配置
1918
814
  * @param resolve 回调
1919
815
  * @param reject 抛出错误
1920
- * @param argumentsList 参数列表
816
+ * @param argsResult 返回的参数列表
1921
817
  */
1922
818
  onLoad(
1923
- details: Required<HttpxDetails>,
1924
- resolve: (...args: any[]) => void,
819
+ details: Required<HttpxRequestOption>,
820
+ resolve: (resultOption: HttpxResponse<HttpxRequestOption>) => void,
1925
821
  reject: (...args: any[]) => void,
1926
- argumentsList: any
822
+ argsResult: any[]
1927
823
  ) {
824
+ // console.log(argsResult);
1928
825
  /* X浏览器会因为设置了responseType导致不返回responseText */
1929
- let originResponse: HttpxAsyncResultData<HttpxDetails> = argumentsList[0];
826
+ let originResponse: HttpxResponseData<HttpxRequestOption> = argsResult[0];
1930
827
  /* responseText为空,response不为空的情况 */
1931
828
  if (
1932
829
  Utils.isNull(originResponse["responseText"]) &&
@@ -1939,7 +836,7 @@ class Httpx {
1939
836
  );
1940
837
  });
1941
838
  } else {
1942
- originResponse["responseText"] = originResponse["response"];
839
+ originResponse["responseText"] = originResponse["response"] as string;
1943
840
  }
1944
841
  }
1945
842
 
@@ -2020,10 +917,11 @@ class Httpx {
2020
917
  return;
2021
918
  }
2022
919
  resolve({
2023
- status: true,
2024
920
  data: originResponse,
2025
921
  details: details,
2026
- msg: "请求完毕",
922
+ msg: "请求成功",
923
+ status: true,
924
+ statusCode: originResponse.status,
2027
925
  type: "onload",
2028
926
  });
2029
927
  } else {
@@ -2031,34 +929,39 @@ class Httpx {
2031
929
  details,
2032
930
  resolve,
2033
931
  reject,
2034
- argumentsList
932
+ argsResult
2035
933
  );
2036
934
  }
2037
935
  },
2038
936
  /**
2039
937
  * onprogress上传进度-触发
2040
938
  * @param details 配置
2041
- * @param argumentsList 参数列表
939
+ * @param argsResult 返回的参数列表
2042
940
  */
2043
- onProgress(details: Required<HttpxDetails>, argumentsList: any) {
941
+ onProgress(details: Required<HttpxRequestOption>, argsResult: any[]) {
942
+ // console.log(argsResult);
2044
943
  if ("onprogress" in details) {
2045
- details.onprogress.apply(this, argumentsList);
944
+ details.onprogress.apply(this, argsResult);
2046
945
  } else if ("onprogress" in this.context.#defaultDetails) {
2047
- this.context.#defaultDetails!.onprogress!.apply(this, argumentsList);
946
+ this.context.#defaultDetails!.onprogress!.apply(this, argsResult);
2048
947
  }
2049
948
  },
2050
949
  /**
2051
950
  * onreadystatechange准备状态改变-触发
2052
951
  * @param details 配置
2053
- * @param argumentsList 参数列表
952
+ * @param argsResult 返回的参数列表
2054
953
  */
2055
- onReadyStateChange(details: Required<HttpxDetails>, argumentsList: any) {
954
+ onReadyStateChange(
955
+ details: Required<HttpxRequestOption>,
956
+ argsResult: any[]
957
+ ) {
958
+ // console.log(argsResult);
2056
959
  if ("onreadystatechange" in details) {
2057
- details.onreadystatechange.apply(this, argumentsList);
960
+ details.onreadystatechange.apply(this, argsResult);
2058
961
  } else if ("onreadystatechange" in this.context.#defaultDetails) {
2059
962
  this.context.#defaultDetails!.onreadystatechange!.apply(
2060
963
  this,
2061
- argumentsList
964
+ argsResult
2062
965
  );
2063
966
  }
2064
967
  },
@@ -2069,7 +972,7 @@ class Httpx {
2069
972
  * 发送请求
2070
973
  * @param details
2071
974
  */
2072
- request(details: Required<HttpxDetails>) {
975
+ request(details: Required<HttpxRequestOption>) {
2073
976
  if (this.context.#LOG_DETAILS) {
2074
977
  console.log("[Httpx-HttpxRequest.request] 请求前的配置👇", details);
2075
978
  }
@@ -2084,11 +987,15 @@ class Httpx {
2084
987
  }
2085
988
  }
2086
989
  if (details.fetch) {
2087
- const { fetchDetails, fetchRequestInit, abortController } =
2088
- this.context.HttpxRequestDetails.handleFetchDetail(details);
2089
- return this.fetch(fetchDetails, fetchRequestInit, abortController);
990
+ // 使用fetch请求
991
+ const {
992
+ fetchOption: fetchOption,
993
+ fetchRequestOption: fetchRequestOption,
994
+ abortController,
995
+ } = this.context.HttpxRequestDetails.handleFetchOption(details);
996
+ return this.fetch(fetchOption, fetchRequestOption, abortController);
2090
997
  } else {
2091
- Reflect.deleteProperty(details, "fetchInit");
998
+ // 使用GM_xmlHttpRequest请求
2092
999
  return this.xmlHttpRequest(details);
2093
1000
  }
2094
1001
  },
@@ -2096,39 +1003,42 @@ class Httpx {
2096
1003
  * 使用油猴函数GM_xmlhttpRequest发送请求
2097
1004
  * @param details
2098
1005
  */
2099
- xmlHttpRequest(details: Required<HttpxDetails>) {
2100
- return this.context.GM_Api.xmlHttpRequest(details);
1006
+ xmlHttpRequest(details: Required<HttpxRequestOption>) {
1007
+ return this.context.GM_Api.xmlHttpRequest(details) as {
1008
+ abort: () => void;
1009
+ };
2101
1010
  },
2102
1011
  /**
2103
1012
  * 使用fetch发送请求
2104
- * @param details
2105
- * @param fetchRequestInit
1013
+ * @param option
1014
+ * @param fetchRequestOption
2106
1015
  * @param abortController
2107
1016
  */
2108
1017
  fetch(
2109
- details: Required<HttpxDetails>,
2110
- fetchRequestInit: RequestInit,
1018
+ option: Required<HttpxRequestOption>,
1019
+ fetchRequestOption: RequestInit,
2111
1020
  abortController: AbortController
2112
1021
  ) {
2113
- fetch(details.url, fetchRequestInit)
1022
+ fetch(option.url, fetchRequestOption)
2114
1023
  .then(async (fetchResponse) => {
2115
1024
  /** 自定义的response */
2116
- let httpxResponse: HttpxAsyncResultData = {
1025
+ let httpxResponse: HttpxResponseData<HttpxRequestOption> = {
2117
1026
  isFetch: true,
2118
1027
  finalUrl: fetchResponse.url,
2119
1028
  readyState: 4,
2120
1029
  // @ts-ignore
2121
1030
  status: fetchResponse.status,
2122
1031
  statusText: fetchResponse.statusText,
1032
+ // @ts-ignore
2123
1033
  response: void 0,
2124
1034
  responseFetchHeaders: fetchResponse.headers,
2125
1035
  responseHeaders: "",
2126
1036
  // @ts-ignore
2127
1037
  responseText: void 0,
2128
- responseType: details.responseType,
1038
+ responseType: option.responseType,
2129
1039
  responseXML: void 0,
2130
1040
  };
2131
- Object.assign(httpxResponse, details.context || {});
1041
+ Object.assign(httpxResponse, option.context || {});
2132
1042
 
2133
1043
  // 把headers转为字符串
2134
1044
  for (const [key, value] of (fetchResponse.headers as any).entries()) {
@@ -2140,7 +1050,7 @@ class Httpx {
2140
1050
 
2141
1051
  /* 如果需要stream,且获取到的是stream,那直接返回 */
2142
1052
  if (
2143
- details.responseType === "stream" ||
1053
+ option.responseType === "stream" ||
2144
1054
  (fetchResponse.headers.has("Content-Type") &&
2145
1055
  fetchResponse.headers
2146
1056
  .get("Content-Type")!
@@ -2150,7 +1060,7 @@ class Httpx {
2150
1060
  Reflect.set(httpxResponse, "response", fetchResponse.body);
2151
1061
  Reflect.deleteProperty(httpxResponse, "responseText");
2152
1062
  Reflect.deleteProperty(httpxResponse, "responseXML");
2153
- details.onload(httpxResponse);
1063
+ option.onload(httpxResponse);
2154
1064
  return;
2155
1065
  }
2156
1066
 
@@ -2182,22 +1092,22 @@ class Httpx {
2182
1092
  responseText = textDecoder.decode(arrayBuffer);
2183
1093
  response = responseText;
2184
1094
 
2185
- if (details.responseType === "arraybuffer") {
1095
+ if (option.responseType === "arraybuffer") {
2186
1096
  // response返回格式是二进制流
2187
1097
  response = arrayBuffer;
2188
- } else if (details.responseType === "blob") {
1098
+ } else if (option.responseType === "blob") {
2189
1099
  // response返回格式是blob
2190
1100
  response = new Blob([arrayBuffer]);
2191
1101
  } else if (
2192
- details.responseType === "json" ||
1102
+ option.responseType === "json" ||
2193
1103
  (typeof fetchResponseType === "string" &&
2194
1104
  fetchResponseType.includes("application/json"))
2195
1105
  ) {
2196
1106
  // response返回格式是JSON格式
2197
1107
  response = Utils.toJSON(responseText);
2198
1108
  } else if (
2199
- details.responseType === "document" ||
2200
- details.responseType == null
1109
+ option.responseType === "document" ||
1110
+ option.responseType == null
2201
1111
  ) {
2202
1112
  // response返回格式是文档格式
2203
1113
  let parser = new DOMParser();
@@ -2212,15 +1122,15 @@ class Httpx {
2212
1122
  Reflect.set(httpxResponse, "responseXML", responseXML);
2213
1123
 
2214
1124
  // 执行回调
2215
- details.onload(httpxResponse);
1125
+ option.onload(httpxResponse);
2216
1126
  })
2217
1127
  .catch((error: any) => {
2218
1128
  if (error.name === "AbortError") {
2219
1129
  return;
2220
1130
  }
2221
- details.onerror({
1131
+ option.onerror({
2222
1132
  isFetch: true,
2223
- finalUrl: details.url,
1133
+ finalUrl: option.url,
2224
1134
  readyState: 4,
2225
1135
  status: 0,
2226
1136
  statusText: "",
@@ -2229,9 +1139,9 @@ class Httpx {
2229
1139
  error: error,
2230
1140
  });
2231
1141
  });
2232
- details.onloadstart({
1142
+ option.onloadstart({
2233
1143
  isFetch: true,
2234
- finalUrl: details.url,
1144
+ finalUrl: option.url,
2235
1145
  readyState: 1,
2236
1146
  responseHeaders: "",
2237
1147
  responseText: "",
@@ -2248,7 +1158,7 @@ class Httpx {
2248
1158
  /**
2249
1159
  * 默认配置
2250
1160
  */
2251
- #defaultDetails = <HttpxDetails>{
1161
+ #defaultDetails = <HttpxRequestOption>{
2252
1162
  url: void 0,
2253
1163
  timeout: 5000,
2254
1164
  async: false,
@@ -2286,31 +1196,29 @@ class Httpx {
2286
1196
  #LOG_DETAILS = false;
2287
1197
  /**
2288
1198
  * 实例化,可传入GM_xmlhttpRequest,未传入则使用window.fetch
2289
- * @param __xmlHttpRequest__
1199
+ * @param xmlHttpRequest
2290
1200
  */
2291
- constructor(__xmlHttpRequest__?: any) {
2292
- if (typeof __xmlHttpRequest__ !== "function") {
1201
+ constructor(xmlHttpRequest?: Function) {
1202
+ if (typeof xmlHttpRequest !== "function") {
2293
1203
  console.warn(
2294
1204
  "[Httpx-constructor] 未传入GM_xmlhttpRequest函数或传入的GM_xmlhttpRequest不是Function,将默认使用window.fetch"
2295
1205
  );
2296
1206
  }
2297
- this.interceptors.request.context = this as any;
2298
- this.interceptors.response.context = this as any;
2299
- this.GM_Api.xmlHttpRequest = __xmlHttpRequest__;
1207
+ this.interceptors.request.context = this;
1208
+ this.interceptors.response.context = this;
1209
+ this.GM_Api.xmlHttpRequest = xmlHttpRequest;
2300
1210
  }
2301
1211
 
2302
1212
  /**
2303
1213
  * 覆盖全局配置
2304
1214
  * @param details 配置
2305
1215
  */
2306
- config(details?: {
2307
- [K in keyof HttpxDetailsConfig]?: HttpxDetailsConfig[K];
2308
- }): void;
1216
+ config(details?: Partial<HttpxRequestOptionConfig>): void;
2309
1217
  /**
2310
1218
  * 覆盖当前配置
2311
1219
  * @param details
2312
1220
  */
2313
- config(details = <HttpxDetailsConfig>{}) {
1221
+ config(details: HttpxRequestOptionConfig = {}) {
2314
1222
  if ("logDetails" in details && typeof details["logDetails"] === "boolean") {
2315
1223
  this.#LOG_DETAILS = details["logDetails"];
2316
1224
  }
@@ -2329,7 +1237,9 @@ class Httpx {
2329
1237
  * 添加拦截器
2330
1238
  * @param fn 设置的请求前回调函数,如果返回配置,则使用返回的配置,如果返回null|undefined,则阻止请求
2331
1239
  */
2332
- use(fn: <T extends Required<HttpxDetails>>(details: T) => void | T) {
1240
+ use(
1241
+ fn: <T extends Required<HttpxRequestOption>>(details: T) => void | T
1242
+ ) {
2333
1243
  if (typeof fn !== "function") {
2334
1244
  console.warn("[Httpx-interceptors-request] 请传入拦截器函数");
2335
1245
  return;
@@ -2363,9 +1273,9 @@ class Httpx {
2363
1273
  * + 超出 2xx 范围的状态码都会触发该函数
2364
1274
  */
2365
1275
  use(
2366
- successFn?: <T extends HttpxAsyncResultData>(
1276
+ successFn?: <T extends HttpxResponseData<HttpxRequestOption>>(
2367
1277
  response: T,
2368
- details: HttpxDetails
1278
+ details: HttpxRequestOption
2369
1279
  ) => void | T,
2370
1280
  errorFn?: <T extends HttpxHookErrorData>(data: T) => void | T
2371
1281
  ) {
@@ -2394,54 +1304,55 @@ class Httpx {
2394
1304
  * 修改xmlHttpRequest
2395
1305
  * @param httpRequest 网络请求函数
2396
1306
  */
2397
- setXMLHttpRequest(httpRequest: any) {
1307
+ setXMLHttpRequest(httpRequest: Function) {
2398
1308
  this.GM_Api.xmlHttpRequest = httpRequest;
2399
1309
  }
2400
1310
  /**
2401
1311
  * GET 请求
2402
1312
  * @param url 网址
2403
1313
  */
2404
- async get(
1314
+ async get<T extends HttpxRequestOption>(
2405
1315
  url: string // @ts-ignore
2406
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1316
+ ): HttpxPromise<HttpxResponse<T>>;
2407
1317
  /**
2408
1318
  * GET 请求
2409
1319
  * @param details 配置
2410
1320
  */
2411
- async get(
2412
- details: HttpxDetails // @ts-ignore
2413
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1321
+ async get<T extends HttpxRequestOption>(
1322
+ details: T // @ts-ignore
1323
+ ): HttpxPromise<HttpxResponse<T>>;
2414
1324
  /**
2415
1325
  * GET 请求
2416
1326
  * @param url 网址
2417
1327
  * @param details 配置
2418
1328
  */
2419
- async get(
1329
+ async get<T extends HttpxRequestOption>(
2420
1330
  url: string,
2421
- details: HttpxDetails // @ts-ignore
2422
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1331
+ details: T // @ts-ignore
1332
+ ): HttpxPromise<HttpxResponse<T>>;
2423
1333
  /**
2424
1334
  * GET 请求
2425
1335
  * @param url 网址
2426
1336
  * @param details 配置
2427
1337
  */
2428
1338
  async get(
2429
- ...args: (string | HttpxDetails)[] // @ts-ignore
2430
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>> {
2431
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
1339
+ ...args: (string | HttpxRequestOption)[] // @ts-ignore
1340
+ ): HttpxPromise<HttpxResponse<HttpxRequestOption>> {
1341
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(
1342
+ ...args
1343
+ );
2432
1344
  let abortFn: Function | null = null;
2433
- const promise = new Promise<HttpxAsyncResult<HttpxDetails>>(
1345
+ let promise = new globalThis.Promise<HttpxResponse<HttpxRequestOption>>(
2434
1346
  (resolve, reject) => {
2435
- let requestDetails = this.HttpxRequestDetails.getDetails(
1347
+ let requestOption = this.HttpxRequestDetails.getRequestOption(
2436
1348
  "GET",
2437
- details,
1349
+ userRequestOption,
2438
1350
  resolve,
2439
1351
  reject
2440
1352
  );
2441
- Reflect.deleteProperty(requestDetails, "onprogress");
2442
- // @ts-ignore
2443
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2444
- const requestResult = this.HttpxRequest.request(requestDetails);
1353
+ Reflect.deleteProperty(requestOption, "onprogress");
1354
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
1355
+ const requestResult = this.HttpxRequest.request(requestOption);
2445
1356
  if (
2446
1357
  requestResult != null &&
2447
1358
  typeof requestResult.abort === "function"
@@ -2450,58 +1361,60 @@ class Httpx {
2450
1361
  }
2451
1362
  }
2452
1363
  );
2453
- Object.defineProperty(promise, "abort", {
2454
- value: () => {
2455
- return () => {
2456
- if (typeof abortFn === "function") {
2457
- abortFn();
2458
- }
2459
- };
2460
- },
2461
- });
1364
+ // @ts-ignore
1365
+ promise.abort = () => {
1366
+ if (typeof abortFn === "function") {
1367
+ abortFn();
1368
+ }
1369
+ };
2462
1370
  return promise;
2463
1371
  }
2464
1372
  /**
2465
1373
  * POST 请求
2466
1374
  * @param details 配置
2467
1375
  */
2468
- async post(
2469
- details: HttpxDetails // @ts-ignore
2470
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1376
+ async post<T extends HttpxRequestOption>(
1377
+ details: T // @ts-ignore
1378
+ ): HttpxPromise<HttpxResponse<T>>;
2471
1379
  /**
2472
1380
  * POST 请求
2473
1381
  * @param url 网址
2474
1382
  */
2475
- // @ts-ignore
2476
- async post(url: string): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1383
+ async post<T extends HttpxRequestOption>(
1384
+ url: string
1385
+ ): // @ts-ignore
1386
+ HttpxPromise<HttpxResponse<T>>;
2477
1387
  /**
2478
1388
  * POST 请求
2479
1389
  * @param url 网址
2480
1390
  * @param details 配置
2481
1391
  */
2482
- async post(
1392
+ async post<T extends HttpxRequestOption>(
2483
1393
  url: string,
2484
- details: HttpxDetails // @ts-ignore
2485
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1394
+ details: T // @ts-ignore
1395
+ ): HttpxPromise<HttpxResponse<T>>;
2486
1396
  /**
2487
1397
  * POST 请求
2488
1398
  */
2489
1399
  async post(
2490
- ...args: (HttpxDetails | string)[] // @ts-ignore
2491
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>> {
2492
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
1400
+ ...args: (HttpxRequestOption | string)[] // @ts-ignore
1401
+ ): HttpxPromise<HttpxResponse<HttpxRequestOption>> {
1402
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(
1403
+ ...args
1404
+ );
2493
1405
  let abortFn: Function | null = null;
2494
- const promise = new Promise<HttpxAsyncResult<HttpxDetails>>(
1406
+ let promise = new Promise<HttpxResponse<HttpxRequestOption>>(
2495
1407
  (resolve, reject) => {
2496
- let requestDetails = this.HttpxRequestDetails.getDetails(
1408
+ let requestOption = this.HttpxRequestDetails.getRequestOption(
2497
1409
  "POST",
2498
- details,
1410
+ userRequestOption,
2499
1411
  resolve,
2500
1412
  reject
2501
1413
  );
2502
1414
  // @ts-ignore
2503
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2504
- const requestResult = this.HttpxRequest.request(requestDetails);
1415
+ requestOption =
1416
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
1417
+ const requestResult = this.HttpxRequest.request(requestOption);
2505
1418
  if (
2506
1419
  requestResult != null &&
2507
1420
  typeof requestResult.abort === "function"
@@ -2510,61 +1423,60 @@ class Httpx {
2510
1423
  }
2511
1424
  }
2512
1425
  );
2513
- Object.defineProperty(promise, "abort", {
2514
- value: () => {
2515
- return () => {
2516
- if (typeof abortFn === "function") {
2517
- abortFn();
2518
- }
2519
- };
2520
- },
2521
- });
1426
+ // @ts-ignore
1427
+ promise.abort = () => {
1428
+ if (typeof abortFn === "function") {
1429
+ abortFn();
1430
+ }
1431
+ };
2522
1432
  return promise;
2523
1433
  }
2524
1434
  /**
2525
1435
  * HEAD 请求
2526
1436
  * @param details 配置
2527
1437
  */
2528
- async head(
2529
- details: HttpxDetails // @ts-ignore
2530
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1438
+ async head<T extends HttpxRequestOption>(
1439
+ details: T // @ts-ignore
1440
+ ): HttpxPromise<HttpxResponse<T>>;
2531
1441
  /**
2532
1442
  * HEAD 请求
2533
1443
  * @param url 网址
2534
1444
  */
2535
- async head(
1445
+ async head<T extends HttpxRequestOption>(
2536
1446
  url: string // @ts-ignore
2537
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1447
+ ): HttpxPromise<HttpxResponse<T>>;
2538
1448
  /**
2539
1449
  * HEAD 请求
2540
1450
  * @param url 网址
2541
1451
  * @param details 配置
2542
1452
  */
2543
- async head(
1453
+ async head<T extends HttpxRequestOption>(
2544
1454
  url: string,
2545
- details: HttpxDetails // @ts-ignore
2546
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1455
+ details: T // @ts-ignore
1456
+ ): HttpxPromise<HttpxResponse<T>>;
2547
1457
  /**
2548
1458
  * HEAD 请求
2549
1459
  */
2550
1460
  async head(
2551
- ...args: (HttpxDetails | string)[] // @ts-ignore
2552
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>> {
2553
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
1461
+ ...args: (HttpxRequestOption | string)[] // @ts-ignore
1462
+ ): HttpxPromise<HttpxResponse<HttpxRequestOption>> {
1463
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(
1464
+ ...args
1465
+ );
2554
1466
  let abortFn: Function | null = null;
2555
-
2556
- const promise = new Promise<HttpxAsyncResult<HttpxDetails>>(
1467
+ let promise = new Promise<HttpxResponse<HttpxRequestOption>>(
2557
1468
  (resolve, reject) => {
2558
- let requestDetails = this.HttpxRequestDetails.getDetails(
1469
+ let requestOption = this.HttpxRequestDetails.getRequestOption(
2559
1470
  "HEAD",
2560
- details,
1471
+ userRequestOption,
2561
1472
  resolve,
2562
1473
  reject
2563
1474
  );
2564
- Reflect.deleteProperty(requestDetails, "onprogress");
1475
+ Reflect.deleteProperty(requestOption, "onprogress");
2565
1476
  // @ts-ignore
2566
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2567
- const requestResult = this.HttpxRequest.request(requestDetails);
1477
+ requestOption =
1478
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
1479
+ const requestResult = this.HttpxRequest.request(requestOption);
2568
1480
  if (
2569
1481
  requestResult != null &&
2570
1482
  typeof requestResult.abort === "function"
@@ -2574,16 +1486,12 @@ class Httpx {
2574
1486
  }
2575
1487
  );
2576
1488
 
2577
- Object.defineProperty(promise, "abort", {
2578
- value: () => {
2579
- return () => {
2580
- if (typeof abortFn === "function") {
2581
- abortFn();
2582
- }
2583
- };
2584
- },
2585
- });
2586
-
1489
+ // @ts-ignore
1490
+ promise.abort = () => {
1491
+ if (typeof abortFn === "function") {
1492
+ abortFn();
1493
+ }
1494
+ };
2587
1495
  return promise;
2588
1496
  }
2589
1497
 
@@ -2591,45 +1499,48 @@ class Httpx {
2591
1499
  * OPTIONS 请求
2592
1500
  * @param details 配置
2593
1501
  */
2594
- options(
2595
- details: HttpxDetails // @ts-ignore
2596
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1502
+ options<T extends HttpxRequestOption>(
1503
+ details: T // @ts-ignore
1504
+ ): HttpxPromise<HttpxResponse<T>>;
2597
1505
  /**
2598
1506
  * OPTIONS 请求
2599
1507
  * @param url 网址
2600
1508
  */
2601
- options(
1509
+ options<T extends HttpxRequestOption>(
2602
1510
  url: string // @ts-ignore
2603
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1511
+ ): HttpxPromise<HttpxResponse<T>>;
2604
1512
  /**
2605
1513
  * OPTIONS 请求
2606
1514
  * @param url 网址
2607
1515
  * @param details 配置
2608
1516
  */
2609
- options(
1517
+ options<T extends HttpxRequestOption>(
2610
1518
  url: string,
2611
- details: HttpxDetails // @ts-ignore
2612
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1519
+ details: T // @ts-ignore
1520
+ ): HttpxPromise<HttpxResponse<T>>;
2613
1521
  /**
2614
1522
  * OPTIONS 请求
2615
1523
  */
2616
1524
  async options(
2617
- ...args: (HttpxDetails | string)[] // @ts-ignore
2618
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>> {
2619
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
1525
+ ...args: (HttpxRequestOption | string)[] // @ts-ignore
1526
+ ): HttpxPromise<HttpxResponse<HttpxRequestOption>> {
1527
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(
1528
+ ...args
1529
+ );
2620
1530
  let abortFn: Function | null = null;
2621
- const promise = new Promise<HttpxAsyncResult<HttpxDetails>>(
1531
+ let promise = new Promise<HttpxResponse<HttpxRequestOption>>(
2622
1532
  (resolve, reject) => {
2623
- let requestDetails = this.HttpxRequestDetails.getDetails(
1533
+ let requestOption = this.HttpxRequestDetails.getRequestOption(
2624
1534
  "OPTIONS",
2625
- details,
1535
+ userRequestOption,
2626
1536
  resolve,
2627
1537
  reject
2628
1538
  );
2629
- Reflect.deleteProperty(requestDetails, "onprogress");
1539
+ Reflect.deleteProperty(requestOption, "onprogress");
2630
1540
  // @ts-ignore
2631
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2632
- const requestResult = this.HttpxRequest.request(requestDetails);
1541
+ requestOption =
1542
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
1543
+ const requestResult = this.HttpxRequest.request(requestOption);
2633
1544
  if (
2634
1545
  requestResult != null &&
2635
1546
  typeof requestResult.abort === "function"
@@ -2638,15 +1549,12 @@ class Httpx {
2638
1549
  }
2639
1550
  }
2640
1551
  );
2641
- Object.defineProperty(promise, "abort", {
2642
- value: () => {
2643
- return () => {
2644
- if (typeof abortFn === "function") {
2645
- abortFn();
2646
- }
2647
- };
2648
- },
2649
- });
1552
+ // @ts-ignore
1553
+ promise.abort = () => {
1554
+ if (typeof abortFn === "function") {
1555
+ abortFn();
1556
+ }
1557
+ };
2650
1558
  return promise;
2651
1559
  }
2652
1560
 
@@ -2654,45 +1562,48 @@ class Httpx {
2654
1562
  * DELETE 请求
2655
1563
  * @param details 配置
2656
1564
  */
2657
- async delete(
2658
- details: HttpxDetails // @ts-ignore
2659
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1565
+ async delete<T extends HttpxRequestOption>(
1566
+ details: T // @ts-ignore
1567
+ ): HttpxPromise<HttpxResponse<T>>;
2660
1568
  /**
2661
1569
  * DELETE 请求
2662
1570
  * @param url 网址
2663
1571
  */
2664
- async delete(
1572
+ async delete<T extends HttpxRequestOption>(
2665
1573
  url: string // @ts-ignore
2666
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1574
+ ): HttpxPromise<HttpxResponse<T>>;
2667
1575
  /**
2668
1576
  * DELETE 请求
2669
1577
  * @param url 网址
2670
1578
  * @param details 配置
2671
1579
  */
2672
- async delete(
1580
+ async delete<T extends HttpxRequestOption>(
2673
1581
  url: string,
2674
- details: HttpxDetails // @ts-ignore
2675
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1582
+ details: T // @ts-ignore
1583
+ ): HttpxPromise<HttpxResponse<T>>;
2676
1584
  /**
2677
1585
  * DELETE 请求
2678
1586
  */
2679
1587
  async delete(
2680
- ...args: (HttpxDetails | string)[] // @ts-ignore
2681
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>> {
2682
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
1588
+ ...args: (HttpxRequestOption | string)[] // @ts-ignore
1589
+ ): HttpxPromise<HttpxResponse<HttpxRequestOption>> {
1590
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(
1591
+ ...args
1592
+ );
2683
1593
  let abortFn: Function | null = null;
2684
- const promise = new Promise<HttpxAsyncResult<HttpxDetails>>(
1594
+ let promise = new Promise<HttpxResponse<HttpxRequestOption>>(
2685
1595
  (resolve, reject) => {
2686
- let requestDetails = this.HttpxRequestDetails.getDetails(
1596
+ let requestOption = this.HttpxRequestDetails.getRequestOption(
2687
1597
  "DELETE",
2688
- details,
1598
+ userRequestOption,
2689
1599
  resolve,
2690
1600
  reject
2691
1601
  );
2692
- Reflect.deleteProperty(requestDetails, "onprogress");
1602
+ Reflect.deleteProperty(requestOption, "onprogress");
2693
1603
  // @ts-ignore
2694
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2695
- const requestResult = this.HttpxRequest.request(requestDetails);
1604
+ requestOption =
1605
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
1606
+ const requestResult = this.HttpxRequest.request(requestOption);
2696
1607
  if (
2697
1608
  requestResult != null &&
2698
1609
  typeof requestResult.abort === "function"
@@ -2702,15 +1613,12 @@ class Httpx {
2702
1613
  }
2703
1614
  );
2704
1615
 
2705
- Object.defineProperty(promise, "abort", {
2706
- value: () => {
2707
- return () => {
2708
- if (typeof abortFn === "function") {
2709
- abortFn();
2710
- }
2711
- };
2712
- },
2713
- });
1616
+ // @ts-ignore
1617
+ promise.abort = () => {
1618
+ if (typeof abortFn === "function") {
1619
+ abortFn();
1620
+ }
1621
+ };
2714
1622
  return promise;
2715
1623
  }
2716
1624
 
@@ -2718,44 +1626,47 @@ class Httpx {
2718
1626
  * PUT 请求
2719
1627
  * @param details 配置
2720
1628
  */
2721
- async put(
2722
- details: HttpxDetails // @ts-ignore
2723
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1629
+ async put<T extends HttpxRequestOption>(
1630
+ details: T // @ts-ignore
1631
+ ): HttpxPromise<HttpxResponse<T>>;
2724
1632
  /**
2725
1633
  * PUT 请求
2726
1634
  * @param url 网址
2727
1635
  */
2728
- async put(
1636
+ async put<T extends HttpxRequestOption>(
2729
1637
  url: string // @ts-ignore
2730
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1638
+ ): HttpxPromise<HttpxResponse<T>>;
2731
1639
  /**
2732
1640
  * PUT 请求
2733
1641
  * @param url 网址
2734
1642
  * @param details 配置
2735
1643
  */
2736
- async put(
1644
+ async put<T extends HttpxRequestOption>(
2737
1645
  url: string,
2738
- details: HttpxDetails // @ts-ignore
2739
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>>;
1646
+ details: T // @ts-ignore
1647
+ ): HttpxPromise<HttpxResponse<T>>;
2740
1648
  /**
2741
1649
  * PUT 请求
2742
1650
  */
2743
1651
  async put(
2744
- ...args: (HttpxDetails | string)[] // @ts-ignore
2745
- ): HttpxPromise<HttpxAsyncResult<HttpxDetails>> {
2746
- let details = this.HttpxRequestDetails.handleBeforeRequestDetails(...args);
1652
+ ...args: (HttpxRequestOption | string)[] // @ts-ignore
1653
+ ): HttpxPromise<HttpxResponse<HttpxRequestOption>> {
1654
+ let userRequestOption = this.HttpxRequestDetails.handleBeforeRequestOption(
1655
+ ...args
1656
+ );
2747
1657
  let abortFn: Function | null = null;
2748
- const promise = new Promise<HttpxAsyncResult<HttpxDetails>>(
1658
+ let promise = new Promise<HttpxResponse<HttpxRequestOption>>(
2749
1659
  (resolve, reject) => {
2750
- let requestDetails = this.HttpxRequestDetails.getDetails(
1660
+ let requestOption = this.HttpxRequestDetails.getRequestOption(
2751
1661
  "PUT",
2752
- details,
1662
+ userRequestOption,
2753
1663
  resolve,
2754
1664
  reject
2755
1665
  );
2756
1666
  // @ts-ignore
2757
- requestDetails = this.HttpxRequestDetails.handle(requestDetails);
2758
- const requestResult = this.HttpxRequest.request(requestDetails);
1667
+ requestOption =
1668
+ this.HttpxRequestDetails.removeRequestNullOption(requestOption);
1669
+ const requestResult = this.HttpxRequest.request(requestOption);
2759
1670
  if (
2760
1671
  requestResult != null &&
2761
1672
  typeof requestResult.abort === "function"
@@ -2764,15 +1675,12 @@ class Httpx {
2764
1675
  }
2765
1676
  }
2766
1677
  );
2767
- Object.defineProperty(promise, "abort", {
2768
- value: () => {
2769
- return () => {
2770
- if (typeof abortFn === "function") {
2771
- abortFn();
2772
- }
2773
- };
2774
- },
2775
- });
1678
+ // @ts-ignore
1679
+ promise.abort = () => {
1680
+ if (typeof abortFn === "function") {
1681
+ abortFn();
1682
+ }
1683
+ };
2776
1684
  return promise;
2777
1685
  }
2778
1686
  }