@mepkg/maxios 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/maxios.js +17 -13
- package/src/tls-client.js +4 -4
package/package.json
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"test:watch": "node --test --watch 'tests/**/*.test.js'"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"axios": "1.16.
|
|
17
|
+
"axios": "1.16.1",
|
|
18
18
|
"hpagent": "^1.2.0",
|
|
19
19
|
"lodash-es": "^4.18.1",
|
|
20
|
-
"melperjs": "^
|
|
20
|
+
"melperjs": "^17.0.0"
|
|
21
21
|
},
|
|
22
|
-
"version": "1.
|
|
22
|
+
"version": "1.2.0"
|
|
23
23
|
}
|
package/src/maxios.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import {HttpProxyAgent, HttpsProxyAgent} from "hpagent";
|
|
2
|
-
import {
|
|
3
|
-
import axios from "axios";
|
|
2
|
+
import {cookiesFromResponse, cookiesToHeader} from "melperjs";
|
|
4
3
|
import {isNil, omitBy} from "lodash-es";
|
|
4
|
+
import axios from "axios";
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export class Maxios {
|
|
8
8
|
constructor(proxy = null, config = {}, cookies = {}) {
|
|
9
9
|
this.proxy = proxy;
|
|
10
10
|
this.cookies = cookies;
|
|
11
|
-
config = config || {};
|
|
11
|
+
this.config = config || {};
|
|
12
|
+
|
|
13
|
+
this.config.responseType = config.responseType || "text";
|
|
14
|
+
this.config.timeout = config.timeout || 10000;
|
|
12
15
|
|
|
13
|
-
const axiosOptions = {
|
|
14
|
-
responseType: 'text',
|
|
15
|
-
timeout: config.timeout ?? 10000
|
|
16
|
-
};
|
|
17
16
|
if (this.proxy) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
try {
|
|
18
|
+
const proxyTimeout = this.config.timeout * 0.75 || undefined;
|
|
19
|
+
this.config.httpsAgent = new HttpsProxyAgent({proxy, timeout: proxyTimeout});
|
|
20
|
+
this.config.httpAgent = new HttpProxyAgent({proxy, timeout: proxyTimeout});
|
|
21
|
+
} catch (e) {
|
|
22
|
+
e.message = "Proxy Error | " + e.message;
|
|
23
|
+
throw e;
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
|
-
this.client = axios.create(
|
|
26
|
+
this.client = axios.create(this.config);
|
|
23
27
|
|
|
24
28
|
this.client.interceptors.request.use((request) => {
|
|
25
29
|
this.#requestCookies(request);
|
|
@@ -99,7 +103,7 @@ export class Maxios {
|
|
|
99
103
|
|
|
100
104
|
#responseCookies = (response) => {
|
|
101
105
|
if (!this.cookies) return;
|
|
102
|
-
const parsed =
|
|
106
|
+
const parsed = cookiesFromResponse(response);
|
|
103
107
|
Object.keys(parsed).forEach(key => {
|
|
104
108
|
if (!parsed[key]) {
|
|
105
109
|
delete parsed[key];
|
|
@@ -112,7 +116,7 @@ export class Maxios {
|
|
|
112
116
|
if (!this.cookies) return;
|
|
113
117
|
request.headers = request.headers || {};
|
|
114
118
|
if (!request.headers.cookie && !request.headers.Cookie) {
|
|
115
|
-
const header =
|
|
119
|
+
const header = cookiesToHeader(this.cookies);
|
|
116
120
|
header && (request.headers.cookie = header);
|
|
117
121
|
}
|
|
118
122
|
}
|
package/src/tls-client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {cookiesFromResponse, cookiesToHeader, Exception} from "melperjs";
|
|
2
2
|
import {isNil, omitBy} from "lodash-es";
|
|
3
3
|
import {maxios} from "./maxios.js";
|
|
4
4
|
|
|
@@ -78,7 +78,7 @@ export class TlsClient {
|
|
|
78
78
|
"proxy": proxy || this.proxy || undefined,
|
|
79
79
|
"impersonate": impersonate || this.config.impersonate,
|
|
80
80
|
"visit": visit || this.config.visit,
|
|
81
|
-
"
|
|
81
|
+
"maxRedirects": maxRedirects,
|
|
82
82
|
"base64": base64 ?? this.config.base64,
|
|
83
83
|
"key": this.tlsServer.key
|
|
84
84
|
};
|
|
@@ -171,7 +171,7 @@ export class TlsClient {
|
|
|
171
171
|
|
|
172
172
|
#responseCookies = (response) => {
|
|
173
173
|
if (!this.cookies) return;
|
|
174
|
-
const parsed =
|
|
174
|
+
const parsed = cookiesFromResponse(response);
|
|
175
175
|
Object.keys(parsed).forEach(key => {
|
|
176
176
|
if (!parsed[key]) {
|
|
177
177
|
delete parsed[key];
|
|
@@ -184,7 +184,7 @@ export class TlsClient {
|
|
|
184
184
|
if (!this.cookies) return;
|
|
185
185
|
request.headers = request.headers || {};
|
|
186
186
|
if (!request.headers.cookie && !request.headers.Cookie) {
|
|
187
|
-
const header =
|
|
187
|
+
const header = cookiesToHeader(this.cookies);
|
|
188
188
|
header && (request.headers.cookie = header);
|
|
189
189
|
}
|
|
190
190
|
}
|