@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.
Files changed (48) hide show
  1. package/LICENSE +21 -21
  2. package/dist/export.d.ts +6 -4
  3. package/dist/export.js +13 -9
  4. package/dist/export.js.map +1 -1
  5. package/dist/fetch.d.ts +27 -27
  6. package/dist/fetch.js +51 -51
  7. package/dist/fetch.js.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.js +17 -17
  10. package/dist/ja3Map.d.ts +12 -0
  11. package/dist/ja3Map.js +16 -0
  12. package/dist/ja3Map.js.map +1 -0
  13. package/dist/libcurl.d.ts +186 -172
  14. package/dist/libcurl.js +364 -350
  15. package/dist/libcurl.js.map +1 -1
  16. package/dist/libcurlWebSocket.d.ts +30 -0
  17. package/dist/libcurlWebSocket.js +83 -0
  18. package/dist/libcurlWebSocket.js.map +1 -0
  19. package/dist/requests.d.ts +101 -82
  20. package/dist/requests.js +372 -248
  21. package/dist/requests.js.map +1 -1
  22. package/dist/utils.d.ts +7 -6
  23. package/dist/utils.js +110 -101
  24. package/dist/utils.js.map +1 -1
  25. package/package.json +48 -41
  26. package/readme.md +79 -79
  27. package/scripts/bindings.js +15 -0
  28. package/scripts/postinstall.js +104 -0
  29. package/binding.gyp +0 -97
  30. package/src/ja3Table.json +0 -102
  31. package/src/libcurl/bao_curl.cpp +0 -338
  32. package/src/libcurl/bao_curl_multi.cpp +0 -123
  33. package/src/libcurl/bao_curl_node_addon.cpp +0 -511
  34. package/src/libcurl/include/bao_curl.h +0 -116
  35. package/src/libcurl/include/curl/Makefile.am +0 -39
  36. package/src/libcurl/include/curl/curl.h +0 -3104
  37. package/src/libcurl/include/curl/curlver.h +0 -77
  38. package/src/libcurl/include/curl/easy.h +0 -123
  39. package/src/libcurl/include/curl/mprintf.h +0 -50
  40. package/src/libcurl/include/curl/multi.h +0 -457
  41. package/src/libcurl/include/curl/options.h +0 -68
  42. package/src/libcurl/include/curl/stdcheaders.h +0 -33
  43. package/src/libcurl/include/curl/system.h +0 -504
  44. package/src/libcurl/include/curl/typecheck-gcc.h +0 -707
  45. package/src/libcurl/include/curl/urlapi.h +0 -145
  46. package/src/libcurl/include/request_tls_utils.h +0 -30
  47. package/src/libcurl/include/utils.h +0 -23
  48. package/src/libcurl/utils.cpp +0 -43
@@ -0,0 +1,104 @@
1
+ const {
2
+ readFileSync
3
+ } = require('fs');
4
+
5
+ const {
6
+ platform,
7
+ arch
8
+ } = process;
9
+ let nativeBinding = null;
10
+ let loadError = null;
11
+
12
+ function isMusl() {
13
+ // For Node 10
14
+ if (!process.report || typeof process.report.getReport !== 'function') {
15
+ try {
16
+ const lddPath = require('child_process').execSync('which ldd').toString().trim();
17
+
18
+ return readFileSync(lddPath, 'utf8').includes('musl');
19
+ } catch (e) {
20
+ return true;
21
+ }
22
+ } else {
23
+ const {
24
+ glibcVersionRuntime
25
+ } = process.report.getReport().header;
26
+ return !glibcVersionRuntime;
27
+ }
28
+ }
29
+
30
+ switch (platform) {
31
+ case 'android':
32
+ throw new Error(`Unsupported architecture on Android ${arch}`);
33
+
34
+ case 'win32':
35
+ switch (arch) {
36
+ case 'x64':
37
+ try {
38
+ nativeBinding = require('@ossiana/node-libcurl-win32-x64-msvc');
39
+ } catch (e) {
40
+ loadError = e;
41
+ }
42
+
43
+ break;
44
+
45
+ default:
46
+ throw new Error(`Unsupported architecture on Windows: ${arch}`);
47
+ }
48
+
49
+ break;
50
+
51
+ case 'darwin':
52
+ switch (arch) {
53
+ case 'x64':
54
+ try {
55
+ nativeBinding = require('@ossiana/node-libcurl-darwin-x64');
56
+ } catch (e) {
57
+ loadError = e;
58
+ }
59
+
60
+ break;
61
+
62
+ default:
63
+ throw new Error(`Unsupported architecture on macOS: ${arch}`);
64
+ }
65
+
66
+ break;
67
+
68
+ case 'freebsd':
69
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`);
70
+
71
+ case 'linux':
72
+ switch (arch) {
73
+ case 'x64':
74
+ if (isMusl()) {
75
+ throw new Error(`Unsupported architecture on Linux: ${arch} musl`);
76
+ } else {
77
+ try {
78
+ nativeBinding = require('@ossiana/node-libcurl-linux-x64-gnu');
79
+ } catch (e) {
80
+ loadError = e;
81
+ }
82
+ }
83
+
84
+ break;
85
+
86
+ default:
87
+ throw new Error(`Unsupported architecture on Linux: ${arch}`);
88
+ }
89
+
90
+ break;
91
+
92
+ default:
93
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`);
94
+ }
95
+
96
+ if (!nativeBinding) {
97
+ if (loadError) {
98
+ throw loadError;
99
+ }
100
+
101
+ throw new Error(`Failed to load native binding`);
102
+ }
103
+
104
+ module.exports = nativeBinding;
package/binding.gyp DELETED
@@ -1,97 +0,0 @@
1
- {
2
- "targets": [
3
- {
4
- "target_name": "bao_curl_node_addon",
5
-
6
- "sources": [
7
- "./src/libcurl/bao_curl_node_addon.cpp",
8
- "./src/libcurl/bao_curl.cpp",
9
- "./src/libcurl/bao_curl_multi.cpp",
10
- "./src/libcurl/utils.cpp",
11
- # "./src/libcurl/curlAsyncWorker.cpp",
12
- ],
13
- "include_dirs": [
14
- "<!@(node -p \"require('node-addon-api').include\")",
15
- "./src/libcurl/include"
16
- ],
17
- 'defines': ["NAPI_CPP_EXCEPTIONS",
18
- "CURL_STATICLIB",
19
- "NGHTTP2_STATICLIB"],
20
- 'conditions':[
21
- ['OS=="win"', {
22
-
23
- "configurations": {
24
- 'Release': {
25
- 'msvs_settings': {
26
- 'VCCLCompilerTool': {
27
- 'DisableSpecificWarnings':['4530','4819'],
28
- 'RuntimeLibrary': '1',
29
- }
30
- }
31
- },
32
- 'Debug': {
33
- 'msvs_settings': {
34
- 'VCCLCompilerTool': {
35
- 'DisableSpecificWarnings':['4530','4819'],
36
- 'RuntimeLibrary': '3',
37
- }
38
- }
39
- },
40
- },
41
- 'libraries': [
42
- # "<(module_root_dir)/lib/Debug/libcurl-d_imp.lib"
43
- "<(module_root_dir)/lib/Release/win32-x64/libcurl_imp.lib"
44
- ],
45
- "copies": [
46
- # {
47
- # "destination": "<(module_root_dir)/build/Debug/",
48
- # "files": [
49
- # "<(module_root_dir)/lib/Debug/libcurl-d.dll"
50
- # ]
51
- # },
52
- {
53
- "destination": "<(module_root_dir)/build/Release/",
54
- "files": [
55
- "<(module_root_dir)/lib/Release/win32-x64/libcurl.dll"
56
- ]
57
- }
58
- ]
59
-
60
- }],
61
- ['OS=="linux"', {
62
-
63
- "configurations": {
64
- 'Release': {
65
- 'cflags': [ '-std=c++11', '-fexceptions', '-frtti', '-Wno-deprecated', '-Wno-unused-variable', '-Wno-unused-but-set-variable', '-Wno-maybe-uninitialized', '-Wno-sign-compare', '-Wno-reorder', '-Wno-extra', '-Wno-switch' ,'-fPIC'],
66
- 'cflags_cc': [ '-std=c++11', '-fexceptions', '-frtti', '-Wno-deprecated', '-Wno-unused-variable', '-Wno-unused-but-set-variable', '-Wno-maybe-uninitialized', '-Wno-sign-compare', '-Wno-reorder', '-Wno-extra', '-Wno-switch','-fPIC']
67
- },
68
- 'Debug': {
69
-
70
- },
71
- },
72
- 'libraries': [
73
- "<(module_root_dir)/lib/Release/linux-x64/libcurl.a",
74
- "<(module_root_dir)/lib/Release/linux-x64/libssl.a",
75
- "<(module_root_dir)/lib/Release/linux-x64/libcrypto.a"
76
- ],
77
-
78
- }],
79
- ['OS=="mac"', {
80
- "configurations": {
81
- 'Release': {
82
- 'cflags': [ '-std=c++11', '-fexceptions', '-frtti', '-Wno-deprecated', '-Wno-unused-variable', '-Wno-unused-but-set-variable', '-Wno-maybe-uninitialized', '-Wno-sign-compare', '-Wno-reorder', '-Wno-extra', '-Wno-switch' ,'-fPIC'],
83
- 'cflags_cc': [ '-std=c++11', '-fexceptions', '-frtti', '-Wno-deprecated', '-Wno-unused-variable', '-Wno-unused-but-set-variable', '-Wno-maybe-uninitialized', '-Wno-sign-compare', '-Wno-reorder', '-Wno-extra', '-Wno-switch','-fPIC'],
84
- },
85
- },
86
- 'libraries': [
87
- "/System/Library/Frameworks/CoreFoundation.framework",
88
- "/System/Library/Frameworks/SystemConfiguration.framework",
89
- "<(module_root_dir)/lib/Release/darwin-x64/libcurl.a",
90
- "<(module_root_dir)/lib/Release/darwin-x64/libssl.a",
91
- "<(module_root_dir)/lib/Release/darwin-x64/libcrypto.a"
92
- ],
93
- }]
94
- ],
95
- }
96
- ]
97
- }
package/src/ja3Table.json DELETED
@@ -1,102 +0,0 @@
1
- {
2
- "tls_version": {
3
- "TLSv1_2": 771,
4
- "TLSv1_3": 772
5
- },
6
- "cipher": {
7
- "TLS_AES_128_GCM_SHA256": 4865,
8
- "TLS_AES_256_GCM_SHA384": 4866,
9
- "TLS_CHACHA20_POLY1305_SHA256": 4867,
10
- "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": 49195,
11
- "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": 49199,
12
- "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": 49196,
13
- "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": 49200,
14
- "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256": 52393,
15
- "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256": 52392,
16
- "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": 49171,
17
- "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": 49172,
18
- "TLS_RSA_WITH_AES_128_GCM_SHA256": 156,
19
- "TLS_RSA_WITH_AES_256_GCM_SHA384": 157,
20
- "TLS_RSA_WITH_AES_128_CBC_SHA": 47,
21
- "TLS_RSA_WITH_AES_256_CBC_SHA": 53,
22
- "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256": 158,
23
- "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384": 159,
24
- "TLS_DHE_RSA_WITH_AES_128_CBC_SHA": 51,
25
- "TLS_DHE_RSA_WITH_AES_256_CBC_SHA": 57,
26
- "TLS_RSA_WITH_3DES_EDE_CBC_SHA": 10,
27
- "TLS_RSA_WITH_AES_128_CCM": 49324,
28
- "TLS_RSA_WITH_AES_128_CCM_8": 49328,
29
- "TLS_RSA_WITH_AES_128_CCM_SHA256": 4868,
30
- "TLS_RSA_WITH_AES_256_CCM": 4869,
31
- "TLS_RSA_WITH_AES_256_CCM_8": 49326,
32
- "TLS_RSA_WITH_AES_256_CCM_SHA384": 4865
33
- },
34
- "extension": {
35
- "Server Name Indication (SNI) Empty Host Name": 0,
36
- "Server Name Indication (SNI) Host Name": 1,
37
- "Supported Elliptic Curves": 2,
38
- "Supported Point Formats": 3,
39
- "Client Certificate URL": 4,
40
- "Renegotiation Indication Extension": 5,
41
- "Certificate Transparency": 6,
42
- "Status Request": 7,
43
- "Signed Certificate Timestamp": 8,
44
- "Client Certificate Type": 9,
45
- "Supported Elliptic Curves for Point Formats": 10,
46
- "Certificate Type": 11,
47
- "Server Certificate Type": 12,
48
- "TLS Extension: Server Name Indication (SNI)": 13,
49
- "Session Ticket": 14,
50
- "Supported Versions": 15,
51
- "Heartbeat": 16,
52
- "Application Layer Protocol Negotiation (ALPN)": 17,
53
- "ALPN": 18,
54
- "Status Request v2": 19,
55
- "Signed Certificate Timestamp v2": 20,
56
- "Maximum Fragment Length": 21,
57
- "Client Certificate Timestamp": 22,
58
- "TLS Extension: Elliptic Curves": 23,
59
- "TLS Extension: EC Point Formats": 24,
60
- "TLS Extension: SRTP": 25,
61
- "TLS1.2 Extension: Signature Algorithms": 26,
62
- "TLS Extension: Encrypt-then-MAC": 27,
63
- "TLS Extension: Extended Master Secret": 28,
64
- "TLS Extension: Token Binding": 29,
65
- "TLS Extension: Cached Information": 30,
66
- "TLS Extension: Certificate Transparency": 31,
67
- "TLS Extension: Application Layer Protocol Negotiation (ALPN)": 32,
68
- "TLS Extension: Status Request": 33,
69
- "TLS Extension: Signed Certificate Timestamp": 34,
70
- "SessionTicket TLS Extension": 35,
71
- "Pre-Shared Key": 36,
72
- "Early Data": 37,
73
- "Supported Groups (renamed from Supported Elliptic Curves in TLS 1.3)": 38,
74
- "Key Share": 39,
75
- "PSK Key Exchange Modes": 40,
76
- "TLS Extension: Trusted CA Indication": 41,
77
- "TLS Extension: Certificate Type": 42,
78
- "TLS Extension: Supported Versions": 43,
79
- "TLS Extension: Padding": 44,
80
- "TLS Extension: SessionTicket TLS Without ClientID": 45,
81
- "TLS Extension: Next Protocol Negotiation": 46,
82
- "RSA Key Share": 47,
83
- "Transport Layer Security (TLS) Protocol": 48,
84
- "Pre-Shared Key for (D)TLS": 49,
85
- "Early Data Indication for (D)TLS": 50,
86
- "TLS1.3 Extension: Signature Algorithms": 51,
87
- "Negotiated TLS 1.3 Protocol Version": 65281
88
- },
89
- "support_group": {
90
- "P-256": 23,
91
- "P-384": 24,
92
- "P-521": 25,
93
- "ffdhe2048": 256,
94
- "ffdhe3072": 257,
95
- "X25519": 29
96
- },
97
- "ec_point_format": {
98
- "uncompressed": 0,
99
- "compressed_fixed": 1,
100
- "compressed_variable": 2
101
- }
102
- }
@@ -1,338 +0,0 @@
1
- #include "bao_curl.h"
2
-
3
- #define CHECK_CURLOK(e) \
4
- { \
5
- CURLcode code = (e); \
6
- this->m_lastCode = code; \
7
- if (this->m_verbose && code != CURLcode::CURLE_OK) \
8
- { \
9
- printf("CURL Error:%s\n", curl_easy_strerror(code)); \
10
- } \
11
- }
12
-
13
- #define CHECK_CURLSHOK(e) \
14
- { \
15
- CURLSHcode code = (e); \
16
- if (this->m_verbose && code != CURLcode::CURLE_OK) \
17
- { \
18
- printf("CURL Error:%s\n", curl_share_strerror(code)); \
19
- } \
20
- }
21
-
22
- NAMESPACE_BAO_START
23
-
24
- size_t write_func(void* ptr, size_t size, size_t nmemb, std::string& stream)
25
- {
26
- const size_t resize = size * nmemb;
27
- std::string html_data(reinterpret_cast<const char*>(ptr), size * nmemb);
28
- stream += html_data;
29
- return resize;
30
- }
31
-
32
- BaoCurl::BaoCurl()
33
- {
34
- this->init();
35
- }
36
-
37
- BaoCurl::~BaoCurl()
38
- {
39
- assert(this->m_pCURL);
40
- if (this->m_pHeaders)
41
- {
42
- curl_slist_free_all(this->m_pHeaders);
43
- this->m_pHeaders = NULL;
44
- }
45
- curl_easy_cleanup(this->m_pCURL);
46
- }
47
-
48
- void BaoCurl::init()
49
- {
50
- this->m_pCURL = curl_easy_init();
51
- assert(this->m_pCURL);
52
- CHECK_CURLSHOK(curl_share_setopt(this->m_pCURL, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS));
53
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_SSL_VERIFYPEER, 0L));
54
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_SSL_VERIFYHOST, 0L));
55
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_SSL_CIPHER_LIST, "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:DH-RSA-AES128-GCM-SHA256:AES128-SHA:AES256-SHA"));
56
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_SSL_EC_CURVES, "X25519:P-256:P-384"));
57
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_ACCEPT_ENCODING, ""));
58
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1));
59
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_COOKIEFILE, NULL));
60
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_PRIVATE, this));
61
- this->setTimeout(15, 15);
62
- }
63
-
64
- void BaoCurl::open(std::string& method, std::string& url)
65
- {
66
- this->m_method = method;
67
- this->m_stream.header = "";
68
- this->m_stream.responseText = "";
69
- this->m_bProxy = false;
70
- this->m_bIsHttps = url.substr(0, 5) == "https";
71
- if (this->m_pHeaders)
72
- {
73
- curl_slist_free_all(this->m_pHeaders);
74
- this->m_pHeaders = NULL;
75
- }
76
-
77
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_COOKIELIST, ""));
78
-
79
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_URL, url.c_str()));
80
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_WRITEFUNCTION, &write_func));
81
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_WRITEDATA, &this->m_stream.responseText));
82
-
83
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_HEADERFUNCTION, &write_func));
84
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_HEADERDATA, &this->m_stream.header));
85
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_POST, method == "POST"));
86
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_CUSTOMREQUEST, method.c_str()));
87
- }
88
-
89
- void BaoCurl::setRequestHeader(std::string& key, std::string& value)
90
- {
91
- this->m_pHeaders = curl_slist_append(this->m_pHeaders, (key + ": " + value).c_str());
92
- }
93
-
94
- void BaoCurl::setRequestHeader(std::string& keyValue)
95
- {
96
- this->m_pHeaders = curl_slist_append(this->m_pHeaders, keyValue.c_str());
97
- }
98
-
99
- void BaoCurl::setRequestHeaders(std::string& header)
100
- {
101
- auto arr = StringSplit(header, "\n");
102
- for (auto arr_b = arr.begin(); arr_b != arr.end(); ++arr_b)
103
- {
104
- std::string arr_mem = *arr_b;
105
- if (arr_mem.size() == 0)
106
- {
107
- continue;
108
- }
109
- setRequestHeader(arr_mem);
110
- }
111
- }
112
-
113
- void BaoCurl::setProxy(std::string& proxy)
114
- {
115
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_PROXY, proxy.c_str()));
116
- this->m_bProxy = true;
117
- }
118
-
119
- void BaoCurl::setProxy(std::string& proxy, std::string& username,
120
- std::string& password)
121
- {
122
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_PROXY, proxy.c_str()));
123
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_PROXYUSERPWD, (username + ":" + password).c_str()));
124
- this->m_bProxy = true;
125
- }
126
-
127
- void BaoCurl::setTimeout(
128
- int connectTime,
129
- int sendTime)
130
- {
131
- /*
132
- CURLOPT_CONNECTTIMEOUT:连接对方主机时的最长等待时间,此设置限制的是建立连接过程的时间,其它过程的时间不在控制范围
133
- CURLOPT_TIMEOUT:整个cURL函数执行过程的最长等待时间,也就是说,这个时间是包含连接等待时间的
134
- CURLOPT_TIMEOUT的值应比CURLOPT_CONNECTTIMEOUT大
135
- */
136
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_CONNECTTIMEOUT, connectTime));
137
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_TIMEOUT, sendTime));
138
- }
139
-
140
- void BaoCurl::sendByte(const char* data, const int len)
141
- {
142
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_HTTPHEADER, this->m_pHeaders));
143
- if (this->m_bProxy)
144
- {
145
- if (this->m_bIsHttps)
146
- {
147
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_HTTPPROXYTUNNEL, 1L));
148
- }
149
- else
150
- {
151
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_PROXYTYPE, CURLPROXY_HTTP));
152
- }
153
- }
154
-
155
- if (this->m_method == "POST" || this->m_method == "PUT" || this->m_method == "PATCH")
156
- {
157
- m_postdata = std::unique_ptr<const char[]>(new char[len]);
158
- memcpy((void *)m_postdata.get(), data, len);
159
-
160
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_POSTFIELDS, m_postdata.get()));
161
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_POSTFIELDSIZE, len));
162
- }
163
- /*CHECK_CURLOK(curl_easy_perform(this->m_pCURL));
164
- curl_slist_free_all(this->m_pHeaders);
165
- this->m_pHeaders = NULL;*/
166
- }
167
-
168
- /* Hostname */
169
- /* Include subdomains */
170
- /* Path */
171
- /* Secure */
172
- /* Expiry in epoch time format. 0 == Session */
173
- /* Name */
174
- /* Value */
175
- void BaoCurl::setCookie(std::string& key, std::string& value, std::string& domain, std::string& path)
176
- {
177
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_COOKIELIST, StringFormat("%s\tTRUE\t%s\tFALSE\t0\t%s\t%s", domain.c_str(), path.c_str(), key.c_str(), value.c_str()).c_str()));
178
- // CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_COOKIELIST, StringFormat("Set-Cookie: %s=%s; domain=%s; path=%s;", key.c_str(), value.c_str(), domain.c_str(), path.c_str()).c_str()));
179
- }
180
-
181
- void BaoCurl::deleteCookie(std::string& key, std::string& domain, std::string& path)
182
- {
183
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_COOKIELIST, StringFormat("%s\tTURE\t%s\tFALSE\t1600000000\t%s\t%s", domain.c_str(), path.c_str(), key.c_str(), "").c_str()));
184
- }
185
-
186
- std::string BaoCurl::getCookies()
187
- {
188
- struct curl_slist* cookies = NULL;
189
- std::string str;
190
- CHECK_CURLOK(curl_easy_getinfo(this->m_pCURL, CURLINFO_COOKIELIST, &cookies));
191
- struct curl_slist* cookiesOrign = cookies;
192
-
193
- if (!cookies)
194
- {
195
- return "";
196
- }
197
- do
198
- {
199
- str += cookies->data;
200
- str += "\n";
201
- cookies = cookies->next;
202
- } while (cookies);
203
- curl_slist_free_all(cookiesOrign);
204
- return str;
205
- }
206
-
207
- std::string BaoCurl::getCookie(std::string& key, std::string& domain, std::string& path)
208
- {
209
- struct curl_slist* cookies = NULL;
210
- std::string str = "";
211
- CHECK_CURLOK(curl_easy_getinfo(this->m_pCURL, CURLINFO_COOKIELIST, &cookies));
212
- struct curl_slist* cookiesOrign = cookies;
213
- if (!cookies)
214
- {
215
- return "";
216
- }
217
- do
218
- {
219
- std::vector<std::string> vt = StringSplit(std::string(cookies->data), "\t");
220
- if (domain.size() != 0)
221
- {
222
- if (domain != vt.at(0))
223
- {
224
- cookies = cookies->next;
225
- continue;
226
- }
227
- }
228
- if (path.size() != 0)
229
- {
230
- if (path != vt.at(2))
231
- {
232
- cookies = cookies->next;
233
- continue;
234
- }
235
- }
236
- if (vt.at(5) == key)
237
- {
238
- str = vt.at(6);
239
- break;
240
- }
241
- cookies = cookies->next;
242
- } while (cookies);
243
- curl_slist_free_all(cookiesOrign);
244
- return str;
245
- }
246
-
247
- long BaoCurl::getResponseStatus()
248
- {
249
- long http_code;
250
- CHECK_CURLOK(curl_easy_getinfo(this->m_pCURL, CURLINFO_RESPONSE_CODE, &http_code));
251
- return http_code;
252
- }
253
- void BaoCurl::reset()
254
- {
255
- curl_easy_cleanup(this->m_pCURL);
256
- this->init();
257
- }
258
-
259
- void BaoCurl::setRedirect(bool isAllow)
260
- {
261
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_FOLLOWLOCATION, isAllow));
262
- }
263
- void BaoCurl::printInnerLogger()
264
- {
265
- this->m_verbose = true;
266
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_VERBOSE, 1L));
267
- }
268
-
269
- void BaoCurl::setHttpVersion(BaoCurl::HttpVersion version)
270
- {
271
- int temp = CURL_HTTP_VERSION_1_1;
272
- switch (version)
273
- {
274
- case BaoCurl::HttpVersion::http1_1:
275
- temp = CURL_HTTP_VERSION_1_1;
276
- break;
277
- case BaoCurl::HttpVersion::http2:
278
- temp = CURL_HTTP_VERSION_2;
279
- break;
280
- default:
281
- printf("error httpVersion!\n");
282
- return;
283
- }
284
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_HTTP_VERSION, temp));
285
- }
286
-
287
- unsigned int BaoCurl::getLastCurlCode()
288
- {
289
- return this->m_lastCode;
290
- }
291
-
292
- const char* BaoCurl::getLastCurlCodeError()
293
- {
294
- return curl_easy_strerror(this->m_lastCode);
295
- }
296
-
297
- curl_off_t BaoCurl::getResponseContentLength()
298
- {
299
- curl_off_t size;
300
- CHECK_CURLOK(curl_easy_getinfo(this->m_pCURL, CURLINFO_SIZE_DOWNLOAD_T, &size));
301
- return size;
302
- }
303
-
304
- void BaoCurl::setInterface(std::string& network)
305
- {
306
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_INTERFACE, network.c_str()));
307
- }
308
-
309
- void BaoCurl::setJA3Fingerprint(
310
- int tls_version, std::string& cipher, std::string& tls13_cipher, std::string& extensions, std::string& support_groups, int ec_point_formats)
311
- {
312
-
313
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_SSLVERSION, CURL_SSLVERSION_MAX_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_1 | CURL_SSLVERSION_MAX_TLSv1_2 | CURL_SSLVERSION_MAX_TLSv1_3));
314
-
315
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_SSL_CIPHER_LIST, cipher.c_str() /* "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:DH-RSA-AES128-GCM-SHA256:AES128-SHA:AES256-SHA" */));
316
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_TLS13_CIPHERS, tls13_cipher.c_str()));
317
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_SSL_EC_CURVES, support_groups.c_str() /* "X25519:P-256:P-384" */));
318
- // extensions unsupport
319
- // ec_point_formats unsupport
320
-
321
- /* char tmp2[26] = {
322
- 25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
323
- }; */
324
- /* for (size_t i = 0; i < 24; i++)
325
- {
326
- tmp2[i] = i+1;
327
- } */
328
- // tmp2[25]=0;
329
-
330
- CHECK_CURLOK(curl_easy_setopt(this->m_pCURL, CURLOPT_TLS_EXTENSION_PERMUTATION/* 10316 */, extensions.c_str()));
331
- }
332
-
333
- void BaoCurl::setOnPublishCallback(BaoCurlOnPublishCallback callback) {
334
- this->m_publishCallback = callback;
335
- }
336
-
337
-
338
- NAMESPACE_BAO_END