@mepkg/maxios 1.1.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 +2 -2
- package/src/maxios.js +13 -8
- package/src/tls-client.js +3 -3
package/package.json
CHANGED
package/src/maxios.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 {
|
|
@@ -10,13 +10,18 @@ export class Maxios {
|
|
|
10
10
|
this.cookies = cookies;
|
|
11
11
|
this.config = config || {};
|
|
12
12
|
|
|
13
|
-
this.config.responseType = "text";
|
|
13
|
+
this.config.responseType = config.responseType || "text";
|
|
14
14
|
this.config.timeout = config.timeout || 10000;
|
|
15
15
|
|
|
16
16
|
if (this.proxy) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
+
}
|
|
20
25
|
}
|
|
21
26
|
this.client = axios.create(this.config);
|
|
22
27
|
|
|
@@ -98,7 +103,7 @@ export class Maxios {
|
|
|
98
103
|
|
|
99
104
|
#responseCookies = (response) => {
|
|
100
105
|
if (!this.cookies) return;
|
|
101
|
-
const parsed =
|
|
106
|
+
const parsed = cookiesFromResponse(response);
|
|
102
107
|
Object.keys(parsed).forEach(key => {
|
|
103
108
|
if (!parsed[key]) {
|
|
104
109
|
delete parsed[key];
|
|
@@ -111,7 +116,7 @@ export class Maxios {
|
|
|
111
116
|
if (!this.cookies) return;
|
|
112
117
|
request.headers = request.headers || {};
|
|
113
118
|
if (!request.headers.cookie && !request.headers.Cookie) {
|
|
114
|
-
const header =
|
|
119
|
+
const header = cookiesToHeader(this.cookies);
|
|
115
120
|
header && (request.headers.cookie = header);
|
|
116
121
|
}
|
|
117
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
|
|
|
@@ -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
|
}
|