xshell 1.0.199 → 1.0.200
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/package.json +1 -1
- package/server.d.ts +5 -2
- package/server.js +7 -3
package/package.json
CHANGED
package/server.d.ts
CHANGED
|
@@ -105,8 +105,9 @@ export declare class Server {
|
|
|
105
105
|
- headers?: 修改 (添加、覆盖、null 值时删除) 请求的 http headers, Record<string, string | null>
|
|
106
106
|
- queries?: 修改 (添加、覆盖、null 值时删除) 请求的 http queries, Record<string, string | null>
|
|
107
107
|
- redirect?: `manual` 重定向处理策略,默认按原样返回给客户端
|
|
108
|
-
- timeout?: `1000 * 5` 请求超时时间,可以传入 0 禁用超时
|
|
109
|
-
|
|
108
|
+
- timeout?: `1000 * 5` 请求超时时间,可以传入 0 禁用超时
|
|
109
|
+
- throw_error?: `false` 在遇到 request 请求错误时直接 throw 出来,而不是自动设置到 response */
|
|
110
|
+
request(ctx: Context, path_url: string | URL, { headers: headers_, redirect, queries, timeout, throw_error }?: ServerRequestOptions): Promise<true>;
|
|
110
111
|
static filter_response_headers(headers: RawResponse['headers']): Record<string, string>;
|
|
111
112
|
/** 提供静态文件
|
|
112
113
|
@example
|
|
@@ -145,4 +146,6 @@ export interface ServerRequestOptions {
|
|
|
145
146
|
queries?: Record<string, string>;
|
|
146
147
|
redirect?: RequestOptions['redirect'];
|
|
147
148
|
timeout?: RequestOptions['timeout'];
|
|
149
|
+
throw_error?: boolean;
|
|
148
150
|
}
|
|
151
|
+
export declare const text_plain: "text/plain; charset=utf-8";
|
package/server.js
CHANGED
|
@@ -303,7 +303,7 @@ export class Server {
|
|
|
303
303
|
if (error.status !== 404)
|
|
304
304
|
console.error(error);
|
|
305
305
|
response.status = error.status || 500;
|
|
306
|
-
response.set('content-type',
|
|
306
|
+
response.set('content-type', text_plain);
|
|
307
307
|
response.body = inspect(error, { colors: false });
|
|
308
308
|
}
|
|
309
309
|
}
|
|
@@ -465,8 +465,9 @@ export class Server {
|
|
|
465
465
|
- headers?: 修改 (添加、覆盖、null 值时删除) 请求的 http headers, Record<string, string | null>
|
|
466
466
|
- queries?: 修改 (添加、覆盖、null 值时删除) 请求的 http queries, Record<string, string | null>
|
|
467
467
|
- redirect?: `manual` 重定向处理策略,默认按原样返回给客户端
|
|
468
|
-
- timeout?: `1000 * 5` 请求超时时间,可以传入 0 禁用超时
|
|
469
|
-
|
|
468
|
+
- timeout?: `1000 * 5` 请求超时时间,可以传入 0 禁用超时
|
|
469
|
+
- throw_error?: `false` 在遇到 request 请求错误时直接 throw 出来,而不是自动设置到 response */
|
|
470
|
+
async request(ctx, path_url, { headers: headers_, redirect = 'manual', queries, timeout, throw_error } = {}) {
|
|
470
471
|
const { request: { method, headers, query, body, ip } } = ctx;
|
|
471
472
|
let { response } = ctx;
|
|
472
473
|
const x_forwarded_for = headers['x-forwarded-for'] ? `${headers['x-forwarded-for']}, ${ip}` : ip;
|
|
@@ -504,6 +505,8 @@ export class Server {
|
|
|
504
505
|
response.body = response_.body;
|
|
505
506
|
}
|
|
506
507
|
catch (error) {
|
|
508
|
+
if (throw_error)
|
|
509
|
+
throw error;
|
|
507
510
|
if (error.response?.status !== 404)
|
|
508
511
|
console.log(error);
|
|
509
512
|
if (error.response) {
|
|
@@ -692,4 +695,5 @@ export class Server {
|
|
|
692
695
|
throw new Error(`端口范围 {${range}} 内没有可用的端口`);
|
|
693
696
|
}
|
|
694
697
|
}
|
|
698
|
+
export const text_plain = 'text/plain; charset=utf-8';
|
|
695
699
|
//# sourceMappingURL=server.js.map
|