@ossiana/node-libcurl 1.1.3-alpha-3 → 1.2.2
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/LICENSE +21 -21
- package/dist/export.d.ts +6 -4
- package/dist/export.js +13 -9
- package/dist/export.js.map +1 -1
- package/dist/fetch.d.ts +27 -27
- package/dist/fetch.js +51 -51
- package/dist/fetch.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +17 -17
- package/dist/ja3Map.d.ts +12 -0
- package/dist/ja3Map.js +16 -0
- package/dist/ja3Map.js.map +1 -0
- package/dist/libcurl.d.ts +186 -172
- package/dist/libcurl.js +364 -350
- package/dist/libcurl.js.map +1 -1
- package/dist/libcurlWebSocket.d.ts +30 -0
- package/dist/libcurlWebSocket.js +83 -0
- package/dist/libcurlWebSocket.js.map +1 -0
- package/dist/requests.d.ts +101 -82
- package/dist/requests.js +372 -248
- package/dist/requests.js.map +1 -1
- package/dist/utils.d.ts +7 -6
- package/dist/utils.js +110 -101
- package/dist/utils.js.map +1 -1
- package/package.json +48 -41
- package/readme.md +79 -79
- package/scripts/bindings.js +15 -0
- package/scripts/postinstall.js +104 -0
- package/binding.gyp +0 -97
- package/src/ja3Table.json +0 -102
- package/src/libcurl/bao_curl.cpp +0 -338
- package/src/libcurl/bao_curl_multi.cpp +0 -123
- package/src/libcurl/bao_curl_node_addon.cpp +0 -511
- package/src/libcurl/include/bao_curl.h +0 -116
- package/src/libcurl/include/curl/Makefile.am +0 -39
- package/src/libcurl/include/curl/curl.h +0 -3104
- package/src/libcurl/include/curl/curlver.h +0 -77
- package/src/libcurl/include/curl/easy.h +0 -123
- package/src/libcurl/include/curl/mprintf.h +0 -50
- package/src/libcurl/include/curl/multi.h +0 -457
- package/src/libcurl/include/curl/options.h +0 -68
- package/src/libcurl/include/curl/stdcheaders.h +0 -33
- package/src/libcurl/include/curl/system.h +0 -504
- package/src/libcurl/include/curl/typecheck-gcc.h +0 -707
- package/src/libcurl/include/curl/urlapi.h +0 -145
- package/src/libcurl/include/request_tls_utils.h +0 -30
- package/src/libcurl/include/utils.h +0 -23
- package/src/libcurl/utils.cpp +0 -43
package/dist/requests.js
CHANGED
|
@@ -1,249 +1,373 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requests = void 0;
|
|
4
|
-
const libcurl_1 = require("./libcurl");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
class requestsResponse {
|
|
7
|
-
curl;
|
|
8
|
-
constructor(curl) {
|
|
9
|
-
this.curl = curl;
|
|
10
|
-
}
|
|
11
|
-
get text() {
|
|
12
|
-
return this.curl.getResponseString();
|
|
13
|
-
}
|
|
14
|
-
get json() {
|
|
15
|
-
return this.curl.getResponseJson();
|
|
16
|
-
}
|
|
17
|
-
get buffer() {
|
|
18
|
-
return this.curl.getResponseBody();
|
|
19
|
-
}
|
|
20
|
-
get headers() {
|
|
21
|
-
return this.curl.getResponseHeaders();
|
|
22
|
-
}
|
|
23
|
-
get headersMap() {
|
|
24
|
-
return this.curl.getResponseHeadersMap();
|
|
25
|
-
}
|
|
26
|
-
get status() {
|
|
27
|
-
return this.curl.getResponseStatus();
|
|
28
|
-
}
|
|
29
|
-
get contentLength() {
|
|
30
|
-
return this.curl.getResponseContentLength();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const assignURLSearchParam = (target, source) => {
|
|
34
|
-
source.forEach((value, key) => {
|
|
35
|
-
target.append(key, value);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
async
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requests = void 0;
|
|
4
|
+
const libcurl_1 = require("./libcurl");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
class requestsResponse {
|
|
7
|
+
curl;
|
|
8
|
+
constructor(curl) {
|
|
9
|
+
this.curl = curl;
|
|
10
|
+
}
|
|
11
|
+
get text() {
|
|
12
|
+
return this.curl.getResponseString();
|
|
13
|
+
}
|
|
14
|
+
get json() {
|
|
15
|
+
return this.curl.getResponseJson();
|
|
16
|
+
}
|
|
17
|
+
get buffer() {
|
|
18
|
+
return this.curl.getResponseBody();
|
|
19
|
+
}
|
|
20
|
+
get headers() {
|
|
21
|
+
return this.curl.getResponseHeaders();
|
|
22
|
+
}
|
|
23
|
+
get headersMap() {
|
|
24
|
+
return this.curl.getResponseHeadersMap();
|
|
25
|
+
}
|
|
26
|
+
get status() {
|
|
27
|
+
return this.curl.getResponseStatus();
|
|
28
|
+
}
|
|
29
|
+
get contentLength() {
|
|
30
|
+
return this.curl.getResponseContentLength();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const assignURLSearchParam = (target, source) => {
|
|
34
|
+
source.forEach((value, key) => {
|
|
35
|
+
target.append(key, value);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const ja3Md5Map = new Map();
|
|
39
|
+
class requests {
|
|
40
|
+
option;
|
|
41
|
+
needSetCookies;
|
|
42
|
+
lastJa3;
|
|
43
|
+
randomJa3;
|
|
44
|
+
retryOption = {
|
|
45
|
+
retryNum: 0,
|
|
46
|
+
conditionCallback(resp) {
|
|
47
|
+
const { status } = resp;
|
|
48
|
+
return status >= 200 && status < 400;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
constructor(option = {}) {
|
|
52
|
+
this.option = { ...option };
|
|
53
|
+
const { cookies, timeout, verbose, redirect = false, proxy, httpVersion, interface: interface_, ja3 } = option;
|
|
54
|
+
const curl = this.option.instance ||= new libcurl_1.LibCurl();
|
|
55
|
+
switch (typeof cookies) {
|
|
56
|
+
case 'string':
|
|
57
|
+
this.needSetCookies = !!cookies;
|
|
58
|
+
break;
|
|
59
|
+
case 'object':
|
|
60
|
+
if (cookies !== null) {
|
|
61
|
+
if (cookies.value) {
|
|
62
|
+
if (cookies.uri) {
|
|
63
|
+
(0, utils_1.libcurlSetCookies)(curl, cookies.value, (0, utils_1.getUriTopLevelHost)(cookies.uri));
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.needSetCookies = !!cookies;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (timeout) {
|
|
75
|
+
curl.setTimeout(timeout, timeout);
|
|
76
|
+
}
|
|
77
|
+
if (verbose) {
|
|
78
|
+
curl.printInnerLogger();
|
|
79
|
+
}
|
|
80
|
+
if (interface_) {
|
|
81
|
+
curl.setInterface(interface_);
|
|
82
|
+
}
|
|
83
|
+
if (typeof httpVersion != 'undefined') {
|
|
84
|
+
curl.setHttpVersion(httpVersion);
|
|
85
|
+
}
|
|
86
|
+
if (redirect) {
|
|
87
|
+
curl.setRedirect(true);
|
|
88
|
+
}
|
|
89
|
+
if (proxy) {
|
|
90
|
+
curl.setProxy(proxy);
|
|
91
|
+
}
|
|
92
|
+
this.randomJa3 = !!ja3;
|
|
93
|
+
if (ja3) {
|
|
94
|
+
this.lastJa3 = ja3;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
static session(option = {}) {
|
|
98
|
+
return new requests(option);
|
|
99
|
+
}
|
|
100
|
+
async sendRequest(method, url, requestOpt) {
|
|
101
|
+
const { instance: curl, cookies, timeout: timeoutOpt, ja3 } = this.option;
|
|
102
|
+
const { headers, data, json, params, timeout, interface: interface_, redirect, proxy, httpVersion } = requestOpt || {};
|
|
103
|
+
if (data && json) {
|
|
104
|
+
throw new libcurl_1.LibCurlError('both data and json exist');
|
|
105
|
+
}
|
|
106
|
+
const url_ = new URL(url);
|
|
107
|
+
if (this.needSetCookies) {
|
|
108
|
+
this.needSetCookies = false;
|
|
109
|
+
(0, utils_1.libcurlSetCookies)(curl, cookies, (0, utils_1.getUriTopLevelHost)(url_));
|
|
110
|
+
}
|
|
111
|
+
if (params) {
|
|
112
|
+
assignURLSearchParam(url_.searchParams, new URLSearchParams(params));
|
|
113
|
+
}
|
|
114
|
+
curl.open(method, url_);
|
|
115
|
+
if (headers) {
|
|
116
|
+
curl.setRequestHeaders(headers);
|
|
117
|
+
}
|
|
118
|
+
if (typeof timeout == 'number') {
|
|
119
|
+
curl.setTimeout(timeout, timeout);
|
|
120
|
+
}
|
|
121
|
+
else if (timeoutOpt) {
|
|
122
|
+
curl.setTimeout(timeoutOpt, timeoutOpt);
|
|
123
|
+
}
|
|
124
|
+
if (typeof interface_ == 'string') {
|
|
125
|
+
curl.setInterface(interface_);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
if (this.option.interface) {
|
|
129
|
+
curl.setInterface(this.option.interface);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (typeof redirect == 'boolean') {
|
|
133
|
+
curl.setRedirect(redirect);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
if (this.option.redirect) {
|
|
137
|
+
curl.setRedirect(this.option.redirect);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (proxy) {
|
|
141
|
+
curl.setProxy(proxy);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
if (this.option.proxy) {
|
|
145
|
+
curl.setProxy(this.option.proxy);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (typeof httpVersion == 'number') {
|
|
149
|
+
curl.setHttpVersion(httpVersion);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
if (this.option.httpVersion) {
|
|
153
|
+
curl.setHttpVersion(this.option.httpVersion);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (ja3) {
|
|
157
|
+
curl.setJA3Fingerprint(ja3);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
if (this.randomJa3) {
|
|
161
|
+
this.lastJa3 = (0, utils_1.libcurlRandomJA3Fingerprint)();
|
|
162
|
+
curl.setJA3Fingerprint(this.lastJa3);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
let hasContentType = false;
|
|
166
|
+
if (headers && (data || json)) {
|
|
167
|
+
const contentTypeFilter = (e) => e.some(e => e.toLocaleLowerCase() == 'content-type');
|
|
168
|
+
if (typeof headers == 'string') {
|
|
169
|
+
hasContentType = /content-type/i.test(headers);
|
|
170
|
+
}
|
|
171
|
+
else if (headers instanceof Map) {
|
|
172
|
+
hasContentType = contentTypeFilter([...headers.keys()]);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
hasContentType = contentTypeFilter(Object.keys(headers));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (json) {
|
|
179
|
+
if (!hasContentType) {
|
|
180
|
+
curl.setRequestHeader('Content-Type', 'application/json');
|
|
181
|
+
}
|
|
182
|
+
await curl.send(json);
|
|
183
|
+
}
|
|
184
|
+
else if (data) {
|
|
185
|
+
let sendData = data;
|
|
186
|
+
if (!hasContentType) {
|
|
187
|
+
if (typeof data == 'string') {
|
|
188
|
+
curl.setRequestHeader('Content-Type', 'text/plain');
|
|
189
|
+
}
|
|
190
|
+
else if (data instanceof URLSearchParams) {
|
|
191
|
+
curl.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
192
|
+
}
|
|
193
|
+
else if (data instanceof Uint8Array) {
|
|
194
|
+
curl.setRequestHeader('Content-Type', 'application/octet-stream');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
curl.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (data instanceof Uint8Array) {
|
|
201
|
+
}
|
|
202
|
+
else if (!(data instanceof URLSearchParams) &&
|
|
203
|
+
typeof data == 'object' && data != null) {
|
|
204
|
+
sendData = Object.keys(data).map((e) => {
|
|
205
|
+
const value = data[e];
|
|
206
|
+
const type = typeof value;
|
|
207
|
+
if (['object', 'boolean'].includes(type)) {
|
|
208
|
+
return [e, JSON.stringify(value)];
|
|
209
|
+
}
|
|
210
|
+
else if (type == 'undefined') {
|
|
211
|
+
return [e, ''];
|
|
212
|
+
}
|
|
213
|
+
else if (['string', 'number'].includes(type)) {
|
|
214
|
+
return [e, value + ''];
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
throw new libcurl_1.LibCurlError(`data unkown type ${type}`);
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
221
|
+
.join('&');
|
|
222
|
+
}
|
|
223
|
+
await curl.send(sendData);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
await curl.send();
|
|
227
|
+
}
|
|
228
|
+
return new requestsResponse(curl);
|
|
229
|
+
}
|
|
230
|
+
static async sendRequestStaic(method, url, requestStaticOpt) {
|
|
231
|
+
return requests.session(requestStaticOpt).sendRequestRetry(method, url, requestStaticOpt);
|
|
232
|
+
}
|
|
233
|
+
async sendRequestRetry(method, url, requestOpt) {
|
|
234
|
+
let isSuccess = false, resp;
|
|
235
|
+
const { retryNum, conditionCallback } = this.retryOption;
|
|
236
|
+
if (retryNum == 0) {
|
|
237
|
+
return this.sendRequest(method, url, requestOpt);
|
|
238
|
+
}
|
|
239
|
+
for (let i = 0; i <= retryNum; i++) {
|
|
240
|
+
try {
|
|
241
|
+
resp = await this.sendRequest(method, url, requestOpt);
|
|
242
|
+
isSuccess = conditionCallback(resp);
|
|
243
|
+
if (isSuccess) {
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (!isSuccess) {
|
|
251
|
+
throw new libcurl_1.LibCurlError(`failed after ${retryNum} retries`);
|
|
252
|
+
}
|
|
253
|
+
return resp;
|
|
254
|
+
}
|
|
255
|
+
static async get(url, requestOpt) {
|
|
256
|
+
return requests.sendRequestStaic('GET', url, requestOpt);
|
|
257
|
+
}
|
|
258
|
+
static async post(url, requestOpt) {
|
|
259
|
+
return requests.sendRequestStaic('POST', url, requestOpt);
|
|
260
|
+
}
|
|
261
|
+
static async put(url, requestOpt) {
|
|
262
|
+
return requests.sendRequestStaic('PUT', url, requestOpt);
|
|
263
|
+
}
|
|
264
|
+
static async patch(url, requestOpt) {
|
|
265
|
+
return requests.sendRequestStaic('PATCH', url, requestOpt);
|
|
266
|
+
}
|
|
267
|
+
static async trace(url, requestOpt) {
|
|
268
|
+
return requests.sendRequestStaic('TRACE', url, requestOpt);
|
|
269
|
+
}
|
|
270
|
+
static async head(url, requestOpt) {
|
|
271
|
+
return requests.sendRequestStaic('HEAD', url, requestOpt);
|
|
272
|
+
}
|
|
273
|
+
static async delete(url, requestOpt) {
|
|
274
|
+
return requests.sendRequestStaic('DELETE', url, requestOpt);
|
|
275
|
+
}
|
|
276
|
+
async get(url, requestOpt) {
|
|
277
|
+
return this.sendRequestRetry('GET', url, requestOpt);
|
|
278
|
+
}
|
|
279
|
+
async post(url, requestOpt) {
|
|
280
|
+
return this.sendRequestRetry('POST', url, requestOpt);
|
|
281
|
+
}
|
|
282
|
+
async put(url, requestOpt) {
|
|
283
|
+
return this.sendRequestRetry('PUT', url, requestOpt);
|
|
284
|
+
}
|
|
285
|
+
async patch(url, requestOpt) {
|
|
286
|
+
return this.sendRequestRetry('PATCH', url, requestOpt);
|
|
287
|
+
}
|
|
288
|
+
async trace(url, requestOpt) {
|
|
289
|
+
return this.sendRequestRetry('TRACE', url, requestOpt);
|
|
290
|
+
}
|
|
291
|
+
async head(url, requestOpt) {
|
|
292
|
+
return this.sendRequestRetry('HEAD', url, requestOpt);
|
|
293
|
+
}
|
|
294
|
+
async delete(url, requestOpt) {
|
|
295
|
+
return this.sendRequestRetry('DELETE', url, requestOpt);
|
|
296
|
+
}
|
|
297
|
+
setCookie(key, value, domain, path = '') {
|
|
298
|
+
this.option.instance.setCookie({
|
|
299
|
+
name: key,
|
|
300
|
+
value,
|
|
301
|
+
domain,
|
|
302
|
+
path,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
getCookie(key, domain, path) {
|
|
306
|
+
return this.option.instance.getCookie({
|
|
307
|
+
name: key,
|
|
308
|
+
domain: domain || "",
|
|
309
|
+
path: path || "",
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
getCookies(domain, path) {
|
|
313
|
+
if (arguments.length == 0) {
|
|
314
|
+
return this.option.instance.getCookies();
|
|
315
|
+
}
|
|
316
|
+
return this.option.instance.getCookies({
|
|
317
|
+
domain: domain || "",
|
|
318
|
+
path: path || "",
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
getCookiesMap(domain, path) {
|
|
322
|
+
if (arguments.length == 0) {
|
|
323
|
+
return this.option.instance.getCookiesMap();
|
|
324
|
+
}
|
|
325
|
+
return this.option.instance.getCookiesMap({
|
|
326
|
+
domain: domain || "",
|
|
327
|
+
path: path || "",
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
deleteCookie(key, domain, path) {
|
|
331
|
+
this.option.instance.deleteCookie({
|
|
332
|
+
name: key,
|
|
333
|
+
domain: domain,
|
|
334
|
+
path: path || "/",
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
getJA3Fingerprint() {
|
|
338
|
+
if (!this.lastJa3) {
|
|
339
|
+
return {
|
|
340
|
+
ja3: '',
|
|
341
|
+
ja3_hash: '',
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
if (!ja3Md5Map.has(this.lastJa3)) {
|
|
345
|
+
const ja3_hash = (0, utils_1.md5)(this.lastJa3);
|
|
346
|
+
ja3Md5Map.set(this.lastJa3, ja3_hash);
|
|
347
|
+
return {
|
|
348
|
+
ja3: this.lastJa3,
|
|
349
|
+
ja3_hash,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
const ja3_hash = ja3Md5Map.get(this.lastJa3);
|
|
353
|
+
return {
|
|
354
|
+
ja3: this.lastJa3,
|
|
355
|
+
ja3_hash,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
retry(retryNum, conditionCallback) {
|
|
359
|
+
if (retryNum < 0) {
|
|
360
|
+
throw new libcurl_1.LibCurlError('retryNum must be great than 0');
|
|
361
|
+
}
|
|
362
|
+
const rq = requests.session({
|
|
363
|
+
...this.option,
|
|
364
|
+
});
|
|
365
|
+
rq.retryOption.retryNum = retryNum;
|
|
366
|
+
if (typeof conditionCallback == 'function') {
|
|
367
|
+
rq.retryOption.conditionCallback = conditionCallback;
|
|
368
|
+
}
|
|
369
|
+
return rq;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
exports.requests = requests;
|
|
249
373
|
//# sourceMappingURL=requests.js.map
|