@ossiana/node-libcurl 1.0.7-alpha-2 → 1.0.8-alpha-1
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 -0
- package/binding.gyp +18 -57
- package/dist/export.d.ts +2 -1
- package/dist/export.js +3 -1
- package/dist/export.js.map +1 -1
- package/dist/fetch.d.ts +4 -13
- package/dist/fetch.js +33 -68
- package/dist/fetch.js.map +1 -1
- package/dist/libcurl.d.ts +64 -11
- package/dist/libcurl.js +87 -47
- package/dist/libcurl.js.map +1 -1
- package/dist/requests.d.ts +66 -0
- package/dist/requests.js +186 -0
- package/dist/requests.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +69 -0
- package/dist/utils.js.map +1 -0
- package/package.json +38 -29
- package/readme.md +36 -9
- package/src/export.ts +3 -3
- package/src/fetch.ts +38 -86
- package/src/libcurl/bao_curl.cpp +58 -22
- package/src/libcurl/bao_curl_node_addon.cpp +20 -13
- package/src/libcurl/curlAsyncWorker.cpp +6 -2
- package/src/libcurl/include/bao_curl.h +41 -38
- package/src/libcurl/include/curlAysncWorker.h +2 -0
- package/src/libcurl.ts +149 -58
- package/src/requests.ts +211 -0
- package/src/utils.ts +71 -0
- package/tsconfig.json +1 -0
- package/dist/src/export.d.ts +0 -3
- package/dist/src/export.js +0 -8
- package/dist/src/export.js.map +0 -1
- package/dist/src/fetch.d.ts +0 -32
- package/dist/src/fetch.js +0 -90
- package/dist/src/fetch.js.map +0 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -18
- package/dist/src/index.js.map +0 -1
- package/dist/src/libcurl.d.ts +0 -31
- package/dist/src/libcurl.js +0 -154
- package/dist/src/libcurl.js.map +0 -1
- package/index.js +0 -1
- package/src/libcurl/lib/Release/darwin/libcrypto.a +0 -0
- package/src/libcurl/lib/Release/darwin/libcurl.a +0 -0
- package/src/libcurl/lib/Release/darwin/libssl.a +0 -0
- package/src/libcurl/lib/Release/linux/libcrypto.a +0 -0
- package/src/libcurl/lib/Release/linux/libcurl.a +0 -0
- package/src/libcurl/lib/Release/linux/libssl.a +0 -0
- package/src/libcurl/lib/Release/windows/libcurl.dll +0 -0
- package/src/libcurl/lib/Release/windows/libcurl_imp.lib +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) node-libcurl Ossianaa Project Contributors. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/binding.gyp
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
'variables': {
|
|
3
|
-
'libcurl_libraries%': '',
|
|
4
|
-
},
|
|
5
2
|
"targets": [
|
|
6
3
|
{
|
|
7
4
|
"target_name": "bao_curl_node_addon",
|
|
8
5
|
|
|
9
6
|
"sources": [
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
7
|
+
"<(module_root_dir)/src/libcurl/bao_curl_node_addon.cpp",
|
|
8
|
+
"<(module_root_dir)/src/libcurl/bao_curl.cpp",
|
|
9
|
+
"<(module_root_dir)/src/libcurl/utils.cpp",
|
|
10
|
+
"<(module_root_dir)/src/libcurl/curlAsyncWorker.cpp",
|
|
14
11
|
],
|
|
15
12
|
"include_dirs": [
|
|
16
13
|
"<!@(node -p \"require('node-addon-api').include\")",
|
|
17
|
-
"
|
|
14
|
+
"<(module_root_dir)/src/libcurl/include"
|
|
18
15
|
],
|
|
19
16
|
'defines': ["NAPI_CPP_EXCEPTIONS",
|
|
20
17
|
"CURL_STATICLIB",
|
|
@@ -27,7 +24,7 @@
|
|
|
27
24
|
'msvs_settings': {
|
|
28
25
|
'VCCLCompilerTool': {
|
|
29
26
|
'DisableSpecificWarnings':['4530','4819'],
|
|
30
|
-
'RuntimeLibrary': '
|
|
27
|
+
'RuntimeLibrary': '1',
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
30
|
},
|
|
@@ -41,20 +38,20 @@
|
|
|
41
38
|
},
|
|
42
39
|
},
|
|
43
40
|
'libraries': [
|
|
44
|
-
# "<(module_root_dir)/
|
|
45
|
-
"<(module_root_dir)/
|
|
41
|
+
# "<(module_root_dir)/lib/Debug/libcurl-d_imp.lib"
|
|
42
|
+
"<(module_root_dir)/lib/Release/win32-x64/libcurl_imp.lib"
|
|
46
43
|
],
|
|
47
44
|
"copies": [
|
|
48
45
|
# {
|
|
49
46
|
# "destination": "<(module_root_dir)/build/Debug/",
|
|
50
47
|
# "files": [
|
|
51
|
-
# "<(module_root_dir)/
|
|
48
|
+
# "<(module_root_dir)/lib/Debug/libcurl-d.dll"
|
|
52
49
|
# ]
|
|
53
50
|
# },
|
|
54
51
|
{
|
|
55
52
|
"destination": "<(module_root_dir)/build/Release/",
|
|
56
53
|
"files": [
|
|
57
|
-
"<(module_root_dir)/
|
|
54
|
+
"<(module_root_dir)/lib/Release/win32-x64/libcurl.dll"
|
|
58
55
|
]
|
|
59
56
|
}
|
|
60
57
|
]
|
|
@@ -64,7 +61,7 @@
|
|
|
64
61
|
|
|
65
62
|
"configurations": {
|
|
66
63
|
'Release': {
|
|
67
|
-
|
|
64
|
+
'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'],
|
|
68
65
|
'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']
|
|
69
66
|
},
|
|
70
67
|
'Debug': {
|
|
@@ -72,25 +69,11 @@
|
|
|
72
69
|
},
|
|
73
70
|
},
|
|
74
71
|
'libraries': [
|
|
75
|
-
|
|
76
|
-
"<(module_root_dir)/
|
|
77
|
-
"<(module_root_dir)/
|
|
78
|
-
"<(module_root_dir)/src/libcurl/lib/Release/linux/libcrypto.a"
|
|
72
|
+
"<(module_root_dir)/lib/Release/linux-x64/libcurl.a",
|
|
73
|
+
"<(module_root_dir)/lib/Release/linux-x64/libssl.a",
|
|
74
|
+
"<(module_root_dir)/lib/Release/linux-x64/libcrypto.a"
|
|
79
75
|
],
|
|
80
|
-
|
|
81
|
-
# {
|
|
82
|
-
# "destination": "<(module_root_dir)/build/Debug/",
|
|
83
|
-
# "files": [
|
|
84
|
-
# "<(module_root_dir)/src/libcurl/lib/Debug/libcurl-d.dll"
|
|
85
|
-
# ]
|
|
86
|
-
# },
|
|
87
|
-
# {
|
|
88
|
-
# "destination": "<(module_root_dir)/build/Release/",
|
|
89
|
-
# "files": [
|
|
90
|
-
# "<(module_root_dir)/src/libcurl/lib/Release/libcurl.so"
|
|
91
|
-
# ]
|
|
92
|
-
# }
|
|
93
|
-
]
|
|
76
|
+
|
|
94
77
|
}],
|
|
95
78
|
['OS=="mac"', {
|
|
96
79
|
"configurations": {
|
|
@@ -102,34 +85,12 @@
|
|
|
102
85
|
'libraries': [
|
|
103
86
|
"/System/Library/Frameworks/CoreFoundation.framework",
|
|
104
87
|
"/System/Library/Frameworks/SystemConfiguration.framework",
|
|
105
|
-
"<(module_root_dir)/
|
|
106
|
-
"<(module_root_dir)/
|
|
107
|
-
"<(module_root_dir)/
|
|
88
|
+
"<(module_root_dir)/lib/Release/darwin-x64/libcurl.a",
|
|
89
|
+
"<(module_root_dir)/lib/Release/darwin-x64/libssl.a",
|
|
90
|
+
"<(module_root_dir)/lib/Release/darwin-x64/libcrypto.a"
|
|
108
91
|
],
|
|
109
92
|
}]
|
|
110
93
|
],
|
|
111
|
-
|
|
112
|
-
# "configurations":{
|
|
113
|
-
# "Release": {
|
|
114
|
-
# "msvs_settings": {
|
|
115
|
-
# "VCCLCompilerTool": {
|
|
116
|
-
# # 多线程 DLL (/MD)
|
|
117
|
-
# #'RuntimeLibrary': '2',
|
|
118
|
-
# 'ExceptionHandling': '1',
|
|
119
|
-
# 'Optimization': 2, # /O2 safe optimization
|
|
120
|
-
# 'FavorSizeOrSpeed': 1, # /Ot, favour speed over size
|
|
121
|
-
# 'InlineFunctionExpansion': 2, # /Ob2, inline anything eligible
|
|
122
|
-
# # /GL, whole program optimization, needed for LTCG
|
|
123
|
-
# 'WholeProgramOptimization': 'true',
|
|
124
|
-
# 'OmitFramePointers': 'true',
|
|
125
|
-
# 'EnableFunctionLevelLinking': 'true',
|
|
126
|
-
# 'EnableIntrinsicFunctions': 'true',
|
|
127
|
-
# 'AdditionalOptions':[
|
|
128
|
-
# ]
|
|
129
|
-
# }
|
|
130
|
-
# }
|
|
131
|
-
# }
|
|
132
|
-
# }
|
|
133
94
|
}
|
|
134
95
|
]
|
|
135
96
|
}
|
package/dist/export.d.ts
CHANGED
package/dist/export.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetch = exports.LibCurl = void 0;
|
|
3
|
+
exports.requests = exports.fetch = exports.LibCurl = void 0;
|
|
4
4
|
const libcurl_1 = require("./libcurl");
|
|
5
5
|
Object.defineProperty(exports, "LibCurl", { enumerable: true, get: function () { return libcurl_1.LibCurl; } });
|
|
6
6
|
const fetch_1 = require("./fetch");
|
|
7
7
|
Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
|
|
8
|
+
const requests_1 = require("./requests");
|
|
9
|
+
Object.defineProperty(exports, "requests", { enumerable: true, get: function () { return requests_1.requests; } });
|
|
8
10
|
//# sourceMappingURL=export.js.map
|
package/dist/export.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"export.js","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AAG1B,wFAHA,iBAAO,OAGA;AAFhB,mCAA+B;AAEb,sFAFT,aAAK,OAES;AADvB,yCAAqC;AACZ,yFADhB,mBAAQ,OACgB"}
|
package/dist/fetch.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import { LibCurl,
|
|
2
|
-
type LibCurlHeadersInfo = [string, string][] | object | string;
|
|
3
|
-
type LibCurlBodyInfo = string | Uint8Array | any;
|
|
4
|
-
type LibCurlCookiesInfo = string | object;
|
|
5
|
-
type LibCurlHttpVersionInfo = LibCurl_HTTP_VERSION;
|
|
6
|
-
type LibCurlProxyWithAccountInfo = {
|
|
7
|
-
proxy: string;
|
|
8
|
-
username: string;
|
|
9
|
-
password: string;
|
|
10
|
-
};
|
|
11
|
-
type LibCurlProxyInfo = string | LibCurlProxyWithAccountInfo;
|
|
1
|
+
import { LibCurl, LibCurlBodyInfo, LibCurlMethodInfo, LibCurlHeadersInfo, LibCurlCookiesAttr, LibCurlHttpVersionInfo, LibCurlProxyInfo, LibCurlCookiesInfo } from "./libcurl";
|
|
12
2
|
interface LibCurlRequestInfo {
|
|
13
|
-
method?:
|
|
3
|
+
method?: LibCurlMethodInfo;
|
|
14
4
|
headers?: LibCurlHeadersInfo;
|
|
15
5
|
body?: LibCurlBodyInfo;
|
|
16
6
|
redirect?: boolean;
|
|
@@ -25,8 +15,9 @@ interface LibCurlResponseInfo {
|
|
|
25
15
|
arraybuffer: () => Promise<ArrayBuffer>;
|
|
26
16
|
text: () => Promise<string>;
|
|
27
17
|
json: () => Promise<object>;
|
|
28
|
-
jsonp: (callbackName?: string) => Promise<object>;
|
|
29
18
|
headers: () => Promise<string>;
|
|
19
|
+
cookies: () => Promise<string>;
|
|
20
|
+
cookiesMap: () => Promise<LibCurlCookiesAttr>;
|
|
30
21
|
}
|
|
31
22
|
export declare function fetch(url: string | URL, request?: LibCurlRequestInfo): Promise<LibCurlResponseInfo>;
|
|
32
23
|
export {};
|
package/dist/fetch.js
CHANGED
|
@@ -11,79 +11,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.fetch = void 0;
|
|
13
13
|
const libcurl_1 = require("./libcurl");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
14
15
|
function fetch(url, request = {}) {
|
|
15
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
17
|
request.instance || (request.instance = new libcurl_1.LibCurl());
|
|
17
18
|
const curl = request.instance;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
if (redirect) {
|
|
35
|
-
curl.setRedirect(true);
|
|
36
|
-
}
|
|
37
|
-
if (httpVersion) {
|
|
38
|
-
curl.setHttpVersion(httpVersion);
|
|
39
|
-
}
|
|
40
|
-
if (openInnerLog) {
|
|
41
|
-
curl.printInnerLogger();
|
|
42
|
-
}
|
|
19
|
+
const { method = "GET", headers, redirect = false, httpVersion = 0, openInnerLog = false, proxy, body, cookies } = request;
|
|
20
|
+
curl.open(method, url + '', true);
|
|
21
|
+
if (headers) {
|
|
22
|
+
curl.setRequestHeaders(headers);
|
|
23
|
+
}
|
|
24
|
+
if (redirect) {
|
|
25
|
+
curl.setRedirect(true);
|
|
26
|
+
}
|
|
27
|
+
if (httpVersion) {
|
|
28
|
+
curl.setHttpVersion(httpVersion);
|
|
29
|
+
}
|
|
30
|
+
if (openInnerLog) {
|
|
31
|
+
curl.printInnerLogger();
|
|
32
|
+
}
|
|
33
|
+
if (cookies) {
|
|
34
|
+
const { hostname } = new URL(url);
|
|
43
35
|
if (cookies) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (proxy) {
|
|
61
|
-
if (typeof proxy == "string") {
|
|
62
|
-
curl.setProxy(proxy);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
const { proxy: proxy_, username, password, } = proxy;
|
|
66
|
-
curl.setProxy(proxy_, username, password);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
let promise;
|
|
70
|
-
if (body) {
|
|
71
|
-
promise = curl.send(body);
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
promise = curl.send();
|
|
75
|
-
}
|
|
76
|
-
promise.then(() => {
|
|
77
|
-
resolve({
|
|
78
|
-
status: () => curl.getResponseStatus(),
|
|
79
|
-
arraybuffer: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseBody().buffer; }),
|
|
80
|
-
text: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseString(); }),
|
|
81
|
-
json: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseJson(); }),
|
|
82
|
-
jsonp: (callbackName) => __awaiter(this, void 0, void 0, function* () { return curl.getResponseJsonp(callbackName); }),
|
|
83
|
-
headers: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseHeaders(); }),
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
});
|
|
36
|
+
(0, utils_1.libcurlSetCookies)(curl, cookies, hostname);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (proxy) {
|
|
40
|
+
curl.setProxy(proxy);
|
|
41
|
+
}
|
|
42
|
+
yield curl.send(body);
|
|
43
|
+
return {
|
|
44
|
+
status: () => curl.getResponseStatus(),
|
|
45
|
+
arraybuffer: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseBody().buffer; }),
|
|
46
|
+
text: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseString(); }),
|
|
47
|
+
json: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseJson(); }),
|
|
48
|
+
headers: () => __awaiter(this, void 0, void 0, function* () { return curl.getResponseHeaders(); }),
|
|
49
|
+
cookies: () => __awaiter(this, void 0, void 0, function* () { return curl.getCookies(); }),
|
|
50
|
+
cookiesMap: () => __awaiter(this, void 0, void 0, function* () { return curl.getCookiesMap(); }),
|
|
51
|
+
};
|
|
87
52
|
});
|
|
88
53
|
}
|
|
89
54
|
exports.fetch = fetch;
|
package/dist/fetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"fetch.js","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA8K;AAC9K,mCAA4C;AA2B5C,SAAsB,KAAK,CAAC,GAAiB,EAAE,UAA8B,EAAE;;QAC3E,OAAO,CAAC,QAAQ,KAAhB,OAAO,CAAC,QAAQ,GAAK,IAAI,iBAAO,EAAE,EAAC;QACnC,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC9B,MAAM,EAAE,MAAM,GAAG,KAAK,EAClB,OAAO,EAAE,QAAQ,GAAG,KAAK,EAAE,WAAW,GAAG,CAAC,EAC1C,YAAY,GAAG,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAC3D,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE,EAAE,IAAI,CAAC,CAAC;QAClC,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;SACnC;QACD,IAAI,QAAQ,EAAE;YACV,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;SAC1B;QACD,IAAI,WAAW,EAAE;YACb,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;SACpC;QACD,IAAI,YAAY,EAAE;YACd,IAAI,CAAC,gBAAgB,EAAE,CAAC;SAC3B;QACD,IAAI,OAAO,EAAE;YACT,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,OAAO,EAAE;gBACT,IAAA,yBAAiB,EAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;aAC9C;SACJ;QACD,IAAI,KAAK,EAAE;YACP,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;SACxB;QACD,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,OAAO;YACH,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE;YACtC,WAAW,EAAE,GAAS,EAAE,gDAAC,OAAA,IAAI,CAAC,eAAe,EAAE,CAAC,MAAM,CAAA,GAAA;YACtD,IAAI,EAAE,GAAS,EAAE,gDAAC,OAAA,IAAI,CAAC,iBAAiB,EAAE,CAAA,GAAA;YAC1C,IAAI,EAAE,GAAS,EAAE,gDAAC,OAAA,IAAI,CAAC,eAAe,EAAE,CAAA,GAAA;YACxC,OAAO,EAAE,GAAS,EAAE,gDAAC,OAAA,IAAI,CAAC,kBAAkB,EAAE,CAAA,GAAA;YAC9C,OAAO,EAAE,GAAS,EAAE,gDAAC,OAAA,IAAI,CAAC,UAAU,EAAE,CAAA,GAAA;YACtC,UAAU,EAAE,GAAS,EAAE,gDAAC,OAAA,IAAI,CAAC,aAAa,EAAE,CAAA,GAAA;SACxB,CAAC;IAE7B,CAAC;CAAA;AAvCD,sBAuCC"}
|
package/dist/libcurl.d.ts
CHANGED
|
@@ -1,31 +1,84 @@
|
|
|
1
|
-
export declare enum
|
|
1
|
+
export declare enum LibCurlHttpVersionInfo {
|
|
2
2
|
http1_1 = 0,
|
|
3
3
|
http2 = 1
|
|
4
4
|
}
|
|
5
|
+
export type LibCurlSetCookieOption = {
|
|
6
|
+
domain?: string;
|
|
7
|
+
path?: string;
|
|
8
|
+
name: string;
|
|
9
|
+
value: string;
|
|
10
|
+
};
|
|
11
|
+
export type LibCurlCookiesInfo = string | {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
14
|
+
export type LibCurlGetCookiesOption = {
|
|
15
|
+
domain?: string;
|
|
16
|
+
path?: string;
|
|
17
|
+
};
|
|
18
|
+
export type LibCurlGetCookieOption = {
|
|
19
|
+
name: string;
|
|
20
|
+
domain: string;
|
|
21
|
+
path?: string;
|
|
22
|
+
};
|
|
23
|
+
export type LibCurlCookieAttrArray = [
|
|
24
|
+
domain: string,
|
|
25
|
+
secure: boolean,
|
|
26
|
+
path: string,
|
|
27
|
+
cors: boolean,
|
|
28
|
+
timestamp: number,
|
|
29
|
+
name: string,
|
|
30
|
+
value: string
|
|
31
|
+
];
|
|
32
|
+
export type LibCurlCookieAttrObject = {
|
|
33
|
+
domain: string;
|
|
34
|
+
secure: boolean;
|
|
35
|
+
path: string;
|
|
36
|
+
cors: boolean;
|
|
37
|
+
timestamp: number;
|
|
38
|
+
value: string;
|
|
39
|
+
};
|
|
40
|
+
export type LibCurlCookiesAttr = Map<string, LibCurlCookieAttrObject>;
|
|
41
|
+
export type LibCurlHeadersAttr = Map<string, string>;
|
|
42
|
+
export type LibCurlHeadersInfo = string | {
|
|
43
|
+
[key: string]: [value: string];
|
|
44
|
+
} | LibCurlHeadersAttr;
|
|
45
|
+
export type LibCurlBodyInfo = string | Uint8Array | URLSearchParams | any;
|
|
46
|
+
export type LibCurlMethodInfo = 'GET' | 'POST' | 'HEAD' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
|
|
47
|
+
export type LibCurlProxyWithAccountInfo = {
|
|
48
|
+
proxy: string;
|
|
49
|
+
username: string;
|
|
50
|
+
password: string;
|
|
51
|
+
};
|
|
52
|
+
export type LibCurlProxyInfo = string | LibCurlProxyWithAccountInfo;
|
|
53
|
+
export type LibCurlURLInfo = string | URL;
|
|
54
|
+
export declare class LibCurlError extends Error {
|
|
55
|
+
constructor(e: string);
|
|
56
|
+
}
|
|
5
57
|
export declare class LibCurl {
|
|
6
58
|
private m_libCurl_impl_;
|
|
7
59
|
private m_isAsync_;
|
|
8
60
|
private m_isSending_;
|
|
9
61
|
constructor();
|
|
10
62
|
private checkSending;
|
|
11
|
-
open(method:
|
|
63
|
+
open(method: LibCurlMethodInfo, url: LibCurlURLInfo, async?: boolean): void;
|
|
12
64
|
setRequestHeader(key: string, value: string): void;
|
|
13
|
-
setRequestHeaders(headers:
|
|
14
|
-
setProxy(
|
|
65
|
+
setRequestHeaders(headers: LibCurlHeadersInfo): void;
|
|
66
|
+
setProxy(proxyOpt: LibCurlProxyInfo): void;
|
|
15
67
|
setTimeout(connectTime: number, sendTime: number): void;
|
|
16
|
-
setCookie(
|
|
17
|
-
|
|
18
|
-
getCookies(): string;
|
|
19
|
-
|
|
68
|
+
setCookie(cookieOpt: LibCurlSetCookieOption): void;
|
|
69
|
+
deleteCookie(cookieOpt: LibCurlGetCookieOption): void;
|
|
70
|
+
getCookies(cookieOpt?: LibCurlGetCookiesOption): string;
|
|
71
|
+
getCookiesMap(cookieOpt?: LibCurlGetCookiesOption): LibCurlCookiesAttr;
|
|
72
|
+
getCookie(cookieOpt: LibCurlGetCookieOption): string;
|
|
20
73
|
getResponseHeaders(): string;
|
|
74
|
+
getResponseHeadersMap(): LibCurlHeadersAttr;
|
|
21
75
|
getResponseStatus(): number;
|
|
22
76
|
reset(): void;
|
|
23
77
|
setRedirect(isAllow: boolean): void;
|
|
24
78
|
printInnerLogger(): void;
|
|
25
|
-
setHttpVersion(version:
|
|
26
|
-
send(body?:
|
|
79
|
+
setHttpVersion(version: LibCurlHttpVersionInfo): void;
|
|
80
|
+
send(body?: LibCurlBodyInfo): Promise<undefined> | undefined;
|
|
27
81
|
getResponseBody(): Uint8Array;
|
|
28
82
|
getResponseString(): string;
|
|
29
83
|
getResponseJson(): Object;
|
|
30
|
-
getResponseJsonp(callbackName?: string): Object;
|
|
31
84
|
}
|
package/dist/libcurl.js
CHANGED
|
@@ -3,14 +3,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LibCurl = exports.
|
|
6
|
+
exports.LibCurl = exports.LibCurlError = exports.LibCurlHttpVersionInfo = void 0;
|
|
7
7
|
const bindings_1 = __importDefault(require("bindings"));
|
|
8
|
+
const utils_1 = require("./utils");
|
|
8
9
|
const { BaoLibCurl } = (0, bindings_1.default)('bao_curl_node_addon');
|
|
9
|
-
var
|
|
10
|
-
(function (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
})(
|
|
10
|
+
var LibCurlHttpVersionInfo;
|
|
11
|
+
(function (LibCurlHttpVersionInfo) {
|
|
12
|
+
LibCurlHttpVersionInfo[LibCurlHttpVersionInfo["http1_1"] = 0] = "http1_1";
|
|
13
|
+
LibCurlHttpVersionInfo[LibCurlHttpVersionInfo["http2"] = 1] = "http2";
|
|
14
|
+
})(LibCurlHttpVersionInfo = exports.LibCurlHttpVersionInfo || (exports.LibCurlHttpVersionInfo = {}));
|
|
15
|
+
class LibCurlError extends Error {
|
|
16
|
+
constructor(e) {
|
|
17
|
+
super(e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.LibCurlError = LibCurlError;
|
|
14
21
|
class LibCurl {
|
|
15
22
|
constructor() {
|
|
16
23
|
this.m_libCurl_impl_ = new BaoLibCurl();
|
|
@@ -22,7 +29,7 @@ class LibCurl {
|
|
|
22
29
|
}
|
|
23
30
|
open(method, url, async = true) {
|
|
24
31
|
this.checkSending();
|
|
25
|
-
this.m_libCurl_impl_.open(method, url);
|
|
32
|
+
this.m_libCurl_impl_.open(method, url + '');
|
|
26
33
|
this.m_isAsync_ = async;
|
|
27
34
|
}
|
|
28
35
|
setRequestHeader(key, value) {
|
|
@@ -31,15 +38,32 @@ class LibCurl {
|
|
|
31
38
|
}
|
|
32
39
|
setRequestHeaders(headers) {
|
|
33
40
|
this.checkSending();
|
|
34
|
-
|
|
41
|
+
if (!headers) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (headers instanceof Map) {
|
|
45
|
+
headers.forEach((value, key) => this.m_libCurl_impl_.setRequestHeader(key, value));
|
|
46
|
+
}
|
|
47
|
+
else if (typeof headers == 'string') {
|
|
48
|
+
this.m_libCurl_impl_.setRequestHeaders(headers);
|
|
49
|
+
}
|
|
50
|
+
else if (typeof headers == 'object') {
|
|
51
|
+
Object.keys(headers).forEach((key) => {
|
|
52
|
+
const value = headers[key];
|
|
53
|
+
this.m_libCurl_impl_.setRequestHeader(key, value);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
throw new TypeError('unkown type');
|
|
58
|
+
}
|
|
35
59
|
}
|
|
36
|
-
setProxy(
|
|
60
|
+
setProxy(proxyOpt) {
|
|
37
61
|
this.checkSending();
|
|
38
|
-
if (
|
|
39
|
-
this.m_libCurl_impl_.setProxy(
|
|
62
|
+
if (typeof proxyOpt == 'string') {
|
|
63
|
+
this.m_libCurl_impl_.setProxy(proxyOpt);
|
|
40
64
|
}
|
|
41
65
|
else {
|
|
42
|
-
this.m_libCurl_impl_.setProxy(proxy);
|
|
66
|
+
this.m_libCurl_impl_.setProxy(proxyOpt.proxy, proxyOpt.username, proxyOpt.password);
|
|
43
67
|
}
|
|
44
68
|
}
|
|
45
69
|
setTimeout(connectTime, sendTime) {
|
|
@@ -49,26 +73,56 @@ class LibCurl {
|
|
|
49
73
|
}
|
|
50
74
|
this.m_libCurl_impl_.setTimeout(connectTime, sendTime);
|
|
51
75
|
}
|
|
52
|
-
setCookie(
|
|
76
|
+
setCookie(cookieOpt) {
|
|
77
|
+
this.checkSending();
|
|
78
|
+
this.m_libCurl_impl_.setCookie(cookieOpt.name, cookieOpt.value, cookieOpt.domain, cookieOpt.path);
|
|
79
|
+
}
|
|
80
|
+
deleteCookie(cookieOpt) {
|
|
53
81
|
this.checkSending();
|
|
54
|
-
this.m_libCurl_impl_.
|
|
82
|
+
this.m_libCurl_impl_.deleteCookie(cookieOpt.name, cookieOpt.domain, cookieOpt.path || "/");
|
|
55
83
|
}
|
|
56
|
-
|
|
84
|
+
getCookies(cookieOpt) {
|
|
57
85
|
this.checkSending();
|
|
58
|
-
this.m_libCurl_impl_.
|
|
86
|
+
const cookies_ = this.m_libCurl_impl_.getCookies();
|
|
87
|
+
return (0, utils_1.httpCookiesToArray)(cookies_).filter((0, utils_1.cookieOptFilter)(cookieOpt)).map(e => `${e[5]}=${encodeURIComponent(e[6])}`).join(';');
|
|
59
88
|
}
|
|
60
|
-
|
|
89
|
+
getCookiesMap(cookieOpt) {
|
|
61
90
|
this.checkSending();
|
|
62
|
-
|
|
91
|
+
const cookies_ = this.m_libCurl_impl_.getCookies();
|
|
92
|
+
return (0, utils_1.httpCookiesToArray)(cookies_).filter((0, utils_1.cookieOptFilter)(cookieOpt)).reduce((e, t) => {
|
|
93
|
+
e.set(t[5], {
|
|
94
|
+
domain: t[0],
|
|
95
|
+
secure: t[1],
|
|
96
|
+
path: t[2],
|
|
97
|
+
cors: t[3],
|
|
98
|
+
timestamp: t[4],
|
|
99
|
+
value: t[6],
|
|
100
|
+
});
|
|
101
|
+
return e;
|
|
102
|
+
}, new Map());
|
|
63
103
|
}
|
|
64
|
-
getCookie(
|
|
104
|
+
getCookie(cookieOpt) {
|
|
65
105
|
this.checkSending();
|
|
66
|
-
return this.m_libCurl_impl_.getCookie(
|
|
106
|
+
return this.m_libCurl_impl_.getCookie(cookieOpt.name, cookieOpt.domain || "", cookieOpt.path || "");
|
|
67
107
|
}
|
|
68
108
|
getResponseHeaders() {
|
|
69
109
|
this.checkSending();
|
|
70
110
|
return this.m_libCurl_impl_.getResponseHeaders();
|
|
71
111
|
}
|
|
112
|
+
getResponseHeadersMap() {
|
|
113
|
+
this.checkSending();
|
|
114
|
+
const headers_ = this.m_libCurl_impl_.getResponseHeaders();
|
|
115
|
+
return headers_.split('\r\n')
|
|
116
|
+
.slice(1)
|
|
117
|
+
.reduce((e, t) => {
|
|
118
|
+
if (!t) {
|
|
119
|
+
return e;
|
|
120
|
+
}
|
|
121
|
+
const [key, value] = t.split(': ');
|
|
122
|
+
e.set(key, value);
|
|
123
|
+
return e;
|
|
124
|
+
}, new Map());
|
|
125
|
+
}
|
|
72
126
|
getResponseStatus() {
|
|
73
127
|
this.checkSending();
|
|
74
128
|
return this.m_libCurl_impl_.getResponseStatus();
|
|
@@ -94,9 +148,14 @@ class LibCurl {
|
|
|
94
148
|
this.m_isSending_ = true;
|
|
95
149
|
if (this.m_isAsync_) {
|
|
96
150
|
return new Promise((resolve, reject) => {
|
|
97
|
-
const callback = () => {
|
|
151
|
+
const callback = (curlcode, curlcodeError) => {
|
|
98
152
|
this.m_isSending_ = false;
|
|
99
|
-
|
|
153
|
+
if (curlcode != 0) {
|
|
154
|
+
reject(new LibCurlError(curlcodeError));
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
resolve(void 0);
|
|
158
|
+
}
|
|
100
159
|
};
|
|
101
160
|
if (body) {
|
|
102
161
|
this.m_libCurl_impl_.sendAsync(body, callback);
|
|
@@ -107,7 +166,12 @@ class LibCurl {
|
|
|
107
166
|
});
|
|
108
167
|
}
|
|
109
168
|
if (body) {
|
|
110
|
-
|
|
169
|
+
if (body instanceof URLSearchParams) {
|
|
170
|
+
this.m_libCurl_impl_.send(body + '');
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
this.m_libCurl_impl_.send(body);
|
|
174
|
+
}
|
|
111
175
|
}
|
|
112
176
|
else {
|
|
113
177
|
this.m_libCurl_impl_.send();
|
|
@@ -125,30 +189,6 @@ class LibCurl {
|
|
|
125
189
|
this.checkSending();
|
|
126
190
|
return JSON.parse(this.getResponseString());
|
|
127
191
|
}
|
|
128
|
-
getResponseJsonp(callbackName) {
|
|
129
|
-
this.checkSending();
|
|
130
|
-
const str = this.getResponseString();
|
|
131
|
-
let jsonstr = str;
|
|
132
|
-
if (callbackName) {
|
|
133
|
-
[, jsonstr] = new RegExp(`\s*${callbackName}[\s\S]*(.*)[\s\S]*`, 'g').exec(str);
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
try {
|
|
137
|
-
eval(str);
|
|
138
|
-
throw new Error('it seem not a jsonp');
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
try {
|
|
142
|
-
[, callbackName] = /(.*) is not defined/g.exec(error.message);
|
|
143
|
-
return this.getResponseJsonp(callbackName);
|
|
144
|
-
}
|
|
145
|
-
catch (_a) {
|
|
146
|
-
throw new Error('it seem not a jsonp');
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return eval(jsonstr);
|
|
151
|
-
}
|
|
152
192
|
}
|
|
153
193
|
exports.LibCurl = LibCurl;
|
|
154
194
|
//# sourceMappingURL=libcurl.js.map
|