xjs-common 9.1.4 → 9.1.6

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.
@@ -19,6 +19,7 @@ export declare class HttpResolverContext implements IHttpClient {
19
19
  * @param op.headers http headers.
20
20
  * @param op.ignoreQuery {@link RequestOption.ignoreQuery}
21
21
  * @param op.downloadPath {@link RequestOption.downloadPath}
22
+ * @param op.timeout {@link RequestOption.timeout}
22
23
  * @returns string encoded by utf-8 as response payload.
23
24
  */
24
25
  get(url: string, op?: RequestOption & {
@@ -31,6 +32,7 @@ export declare class HttpResolverContext implements IHttpClient {
31
32
  * @param op.headers http headers.
32
33
  * @param op.ignoreQuery {@link RequestOption.ignoreQuery}
33
34
  * @param op.downloadPath {@link RequestOption.downloadPath}
35
+ * @param op.timeout {@link RequestOption.timeout}
34
36
  * @returns string encoded by utf-8 as response payload.
35
37
  */
36
38
  post(url: string, payload: any, op?: RequestOption): Promise<HttpResponse>;
@@ -39,12 +39,12 @@ const http_method_1 = require("../../const/http-method");
39
39
  const u_type_1 = require("../../func/u-type");
40
40
  const u_file_1 = require("../../func/u-file");
41
41
  const u_string_1 = require("../../func/u-string");
42
+ const u_1 = require("../../func/u");
42
43
  exports.s_clientMode = {
43
44
  nodejs: { id: 0, cipherOrder: null },
44
45
  chrome: { id: 1, cipherOrder: [2, 0, 1] },
45
46
  firefox: { id: 2, cipherOrder: [2, 1, 0] }
46
47
  };
47
- const s_timeout = 1000 * 20;
48
48
  const s_errCode = 200;
49
49
  const s_redirectLimit = 5;
50
50
  const s_mode2headers = new Map([
@@ -96,7 +96,8 @@ class HttpResolverContext {
96
96
  this.cmv = cmv;
97
97
  this._l = _l;
98
98
  this._mode = op?.mode ?? u_array_1.UArray.randomPick([exports.s_clientMode.chrome, exports.s_clientMode.firefox]);
99
- this._ciphers = this.createCiphers(this._mode);
99
+ if (this._mode.id > 0)
100
+ this._ciphers = this.createCiphers(this._mode);
100
101
  this._proxyConfig = op?.proxy;
101
102
  this._chHeaders = s_mode2headers.get(this._mode)(this.cmv);
102
103
  }
@@ -106,6 +107,7 @@ class HttpResolverContext {
106
107
  * @param op.headers http headers.
107
108
  * @param op.ignoreQuery {@link RequestOption.ignoreQuery}
108
109
  * @param op.downloadPath {@link RequestOption.downloadPath}
110
+ * @param op.timeout {@link RequestOption.timeout}
109
111
  * @returns string encoded by utf-8 as response payload.
110
112
  */
111
113
  async get(url, op) {
@@ -122,6 +124,7 @@ class HttpResolverContext {
122
124
  * @param op.headers http headers.
123
125
  * @param op.ignoreQuery {@link RequestOption.ignoreQuery}
124
126
  * @param op.downloadPath {@link RequestOption.downloadPath}
127
+ * @param op.timeout {@link RequestOption.timeout}
125
128
  * @returns string encoded by utf-8 as response payload.
126
129
  */
127
130
  async post(url, payload, op) {
@@ -179,7 +182,7 @@ class HttpResolverContext {
179
182
  };
180
183
  reqHttps(u, params, payload) {
181
184
  const rc = this._als.getStore();
182
- params.timeout = s_timeout;
185
+ params.timeout = rc.timeout ?? 0;
183
186
  params.protocol = u.protocol;
184
187
  params.host = u.host;
185
188
  params.path = (rc.ignoreQuery || !u.search) ? u.pathname : `${u.pathname}${u.search}`;
@@ -259,7 +262,7 @@ class HttpResolverContext {
259
262
  .find(f => f.trim().startsWith("filename"))
260
263
  ?.replace(/^\s+filename\s+=/, "").trim()
261
264
  ?? u_file_1.UFile.reserveFilePath(d, `xjs-download_${u_string_1.UString.simpleTime()}`);
262
- return u_file_1.UFile.joinPath(d, fname);
265
+ return (0, u_1.joinPath)(d, fname);
263
266
  };
264
267
  if (opPath) {
265
268
  const st = u_file_1.UFile.status(opPath);
@@ -16,6 +16,10 @@ export interface RequestOption {
16
16
  * default is current directory of the process with `filename` of the disposition.
17
17
  */
18
18
  downloadPath?: string;
19
+ /**
20
+ * timeout milliseconds to wait for socket inactivity. default is infinity.
21
+ */
22
+ timeout?: number;
19
23
  }
20
24
  export interface HttpResponse {
21
25
  /**
@@ -36,6 +40,7 @@ export interface IHttpClient {
36
40
  * @param op.proxy proxy configuration.
37
41
  * @param op.ignoreQuery {@link RequestOption.ignoreQuery}
38
42
  * @param op.downloadPath {@link RequestOption.downloadPath}
43
+ * @param op.timeout {@link RequestOption.timeout}
39
44
  * @param op.redirectAsNewRequest handle redirect as new request. this may be efficient when using proxy which is implemented reverse proxy.
40
45
  * @returns http response. {@link HttpResponse}
41
46
  */
@@ -51,6 +56,7 @@ export interface IHttpClient {
51
56
  * @param op.proxy proxy configuration.
52
57
  * @param op.ignoreQuery {@link RequestOption.ignoreQuery}
53
58
  * @param op.downloadPath {@link RequestOption.downloadPath}
59
+ * @param op.timeout {@link RequestOption.timeout}
54
60
  * @returns http response. {@link HttpResponse}
55
61
  */
56
62
  post(url: string, payload: any, op?: RequestOption & ClientOption): Promise<HttpResponse>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xjs-common",
3
- "version": "9.1.4",
3
+ "version": "9.1.6",
4
4
  "description": "library modules for nodejs + typescript that bundled general-purpose implementations.",
5
5
  "repository": {
6
6
  "type": "git",