xshell 1.2.46 → 1.2.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/net.d.ts +4 -4
- package/net.js +17 -17
- package/package.json +1 -1
- package/tsconfig.json +4 -0
package/net.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export interface RequestOptions {
|
|
|
44
44
|
method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'PATCH';
|
|
45
45
|
queries?: Record<string, any>;
|
|
46
46
|
headers?: Record<string, string>;
|
|
47
|
-
body?: string | Record<string, any> | Uint8Array | URLSearchParams |
|
|
47
|
+
body?: string | Record<string, any> | Uint8Array | URLSearchParams | Readable;
|
|
48
48
|
type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data';
|
|
49
49
|
proxy?: boolean | MyProxy | string;
|
|
50
50
|
encoding?: Encoding | 'binary';
|
|
@@ -89,7 +89,7 @@ export declare class StatusCodeError extends Error {
|
|
|
89
89
|
- Uint8Array
|
|
90
90
|
- Record<string, any>: 会自动 JSON.stringify
|
|
91
91
|
- URLSearchParams: 仅限 type 为 x-www-form-urlencoded
|
|
92
|
-
- FormData: 仅限 type 为 form-data
|
|
92
|
+
- Record<string, string | Blob | File> 自动转为 FormData: 仅限 type 为 form-data, 可以传 File 对象设置文件名
|
|
93
93
|
- type?: `'application/json'` 有 body 时设置 http 请求头中的 content-type 头
|
|
94
94
|
- proxy?: `false` 通过代理发送请求
|
|
95
95
|
- 为 true 时使用 MyProxy.socks5
|
|
@@ -103,7 +103,7 @@ export declare class StatusCodeError extends Error {
|
|
|
103
103
|
- cookies?: 需要额外添加到请求的 cookies, 默认情况下携带了 MemoryCookieStore 中保存的之前 http 响应中的 cookies
|
|
104
104
|
- raw?: `false` 传入后返回整个 response (RawResponse),body 为 Readable
|
|
105
105
|
- full?: `false` 传入后返回整个 response (FullResponse),body 根据 encoding 对应为 string 或 Buffer
|
|
106
|
-
- decode?: 根据 content-encoding: br 等解码压缩后的 response.body
|
|
106
|
+
- decode?: `true` 根据 content-encoding: br 等解码压缩后的 response.body
|
|
107
107
|
- print?:
|
|
108
108
|
- retry: `true` 是否打印 "等待 1 秒后重试 request" 提示信息
|
|
109
109
|
- timeout: `true` 是否打印最后一次超时重试失败时的错误 */
|
|
@@ -297,5 +297,5 @@ export declare class RemoteClient {
|
|
|
297
297
|
[inspect.custom](): {
|
|
298
298
|
remote: string;
|
|
299
299
|
websocket: string;
|
|
300
|
-
} & Omit<this,
|
|
300
|
+
} & Omit<this, typeof import("util").inspect.custom | "websocket" | "remote" | "call" | "send">;
|
|
301
301
|
}
|
package/net.js
CHANGED
|
@@ -41,8 +41,7 @@ const drop_request_headers = new Set([
|
|
|
41
41
|
]);
|
|
42
42
|
let agents = {};
|
|
43
43
|
async function request_retry(url, options, _timeout, retries = 0, count = 0, print) {
|
|
44
|
-
|
|
45
|
-
undici_request ??= undici.request;
|
|
44
|
+
const { default: undici } = await import('undici');
|
|
46
45
|
try {
|
|
47
46
|
if (_timeout > 0) {
|
|
48
47
|
// 设置给 undici 设置 timeout, signal 不一定管用,还是得自己兜底
|
|
@@ -81,9 +80,9 @@ export class StatusCodeError extends Error {
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
export async function request(url, options = {}) {
|
|
84
|
-
let { default: undici, ProxyAgent: UndiciProxyAgent, FormData } = await import('undici');
|
|
83
|
+
let { default: undici, ProxyAgent: UndiciProxyAgent, FormData: UndiciFormData } = await import('undici');
|
|
85
84
|
UndiciProxyAgent ??= undici.ProxyAgent;
|
|
86
|
-
|
|
85
|
+
UndiciFormData ??= undici.FormData;
|
|
87
86
|
const { Cookie } = await import('tough-cookie');
|
|
88
87
|
await cookies.init();
|
|
89
88
|
const { queries, headers: _headers, body, type = 'application/json', timeout = 5 * 1000, auth, cookies: _cookies, raw = false, full = false, redirect = 'follow', decode = true, print = {
|
|
@@ -108,11 +107,15 @@ export async function request(url, options = {}) {
|
|
|
108
107
|
let headers = {
|
|
109
108
|
'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',
|
|
110
109
|
'accept-encoding': 'gzip, deflate, br',
|
|
111
|
-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
110
|
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36',
|
|
112
111
|
'sec-ch-ua-platform': '"Windows"',
|
|
113
|
-
'sec-ch-ua-platform-version': '"
|
|
112
|
+
'sec-ch-ua-platform-version': '"19.0.0"',
|
|
114
113
|
};
|
|
115
|
-
|
|
114
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest_API/Using_FormData_Objects
|
|
115
|
+
// When using FormData to submit POST requests using XMLHttpRequest or the Fetch API with the multipart/form-data content type (e.g., when uploading files and blobs to the server),
|
|
116
|
+
// do not explicitly set the Content-Type header on the request.
|
|
117
|
+
// Doing so will prevent the browser from being able to set the Content-Type header with the boundary expression it will use to delimit form fields in the request body.
|
|
118
|
+
if (body !== undefined && type !== 'multipart/form-data')
|
|
116
119
|
headers['content-type'] = type;
|
|
117
120
|
if (auth)
|
|
118
121
|
headers.authorization = auth.type === 'basic' ?
|
|
@@ -178,17 +181,14 @@ export async function request(url, options = {}) {
|
|
|
178
181
|
return JSON.stringify(body);
|
|
179
182
|
case 'application/x-www-form-urlencoded':
|
|
180
183
|
return (body instanceof URLSearchParams ? body : new URLSearchParams(body)).toString();
|
|
181
|
-
case 'multipart/form-data':
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
form.set(key, body[key]);
|
|
188
|
-
return form;
|
|
189
|
-
}
|
|
184
|
+
case 'multipart/form-data': {
|
|
185
|
+
let form = new UndiciFormData();
|
|
186
|
+
for (const key in body)
|
|
187
|
+
form.set(key, body[key]);
|
|
188
|
+
return form;
|
|
189
|
+
}
|
|
190
190
|
}
|
|
191
|
-
})()
|
|
191
|
+
})()
|
|
192
192
|
};
|
|
193
193
|
let response;
|
|
194
194
|
try {
|
package/package.json
CHANGED