@ossiana/node-libcurl 1.0.6-alpha-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/binding.gyp +89 -0
- package/dist/src/export.d.ts +3 -0
- package/dist/src/export.js +8 -0
- package/dist/src/export.js.map +1 -0
- package/dist/src/fetch.d.ts +32 -0
- package/dist/src/fetch.js +90 -0
- package/dist/src/fetch.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +5 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/libcurl.d.ts +31 -0
- package/dist/src/libcurl.js +149 -0
- package/dist/src/libcurl.js.map +1 -0
- package/index.js +1 -0
- package/package.json +29 -0
- package/readme.md +68 -0
- package/src/export.ts +4 -0
- package/src/fetch.ts +116 -0
- package/src/libcurl/bao_curl.cpp +263 -0
- package/src/libcurl/bao_curl_node_addon.cpp +427 -0
- package/src/libcurl/curlAsyncWorker.cpp +31 -0
- package/src/libcurl/include/bao_curl.h +82 -0
- package/src/libcurl/include/curl/Makefile.am +39 -0
- package/src/libcurl/include/curl/curl.h +3103 -0
- package/src/libcurl/include/curl/curlver.h +77 -0
- package/src/libcurl/include/curl/easy.h +123 -0
- package/src/libcurl/include/curl/mprintf.h +50 -0
- package/src/libcurl/include/curl/multi.h +457 -0
- package/src/libcurl/include/curl/options.h +68 -0
- package/src/libcurl/include/curl/stdcheaders.h +33 -0
- package/src/libcurl/include/curl/system.h +504 -0
- package/src/libcurl/include/curl/typecheck-gcc.h +707 -0
- package/src/libcurl/include/curl/urlapi.h +145 -0
- package/src/libcurl/include/curlAysncWorker.h +14 -0
- package/src/libcurl/include/request_tls_utils.h +30 -0
- package/src/libcurl/include/utils.h +13 -0
- package/src/libcurl/lib/Release/libcurl.dll +0 -0
- package/src/libcurl/lib/Release/libcurl_imp.lib +0 -0
- package/src/libcurl/utils.cpp +41 -0
- package/src/libcurl.ts +235 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#include "curlAysncWorker.h"
|
|
2
|
+
|
|
3
|
+
curlAsyncWorker::curlAsyncWorker(Napi::Function &callback, BaoCurl &baoCurlInstance, Napi::Uint8Array body)
|
|
4
|
+
: Napi::AsyncWorker(callback), m_baoCurlInstance(baoCurlInstance), m_sendBody(body) {}
|
|
5
|
+
|
|
6
|
+
curlAsyncWorker::~curlAsyncWorker() {}
|
|
7
|
+
|
|
8
|
+
// Executed inside the worker-thread.
|
|
9
|
+
// It is not safe to access JS engine data structure
|
|
10
|
+
// here, so everything we need for input and output
|
|
11
|
+
// should go on `this`.
|
|
12
|
+
void curlAsyncWorker::Execute()
|
|
13
|
+
{
|
|
14
|
+
this->m_baoCurlInstance.sendByte((const char *)this->m_sendBody.Data(), this->m_sendBody.ByteLength());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Executed when the async work is complete
|
|
18
|
+
// this function will be run inside the main event loop
|
|
19
|
+
// so it is safe to use JS engine data again
|
|
20
|
+
void curlAsyncWorker::OnOK()
|
|
21
|
+
{
|
|
22
|
+
Napi::HandleScope scope(Env());
|
|
23
|
+
/* std::string str = this->m_baoCurlInstance.getResponseBody();
|
|
24
|
+
size_t strLen = str.size();
|
|
25
|
+
Napi::Uint8Array u8buffer = Napi::Uint8Array::New(Env(), strLen);
|
|
26
|
+
memcpy_s(u8buffer.Data(), strLen, str.c_str(), strLen); */
|
|
27
|
+
Callback().Call({
|
|
28
|
+
/* u8buffer */
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#ifndef _CURL_H
|
|
3
|
+
#define _CURL_H
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
#include "curl/curl.h"
|
|
8
|
+
#include "utils.h"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
struct Stream_st {
|
|
12
|
+
std::string header;
|
|
13
|
+
std::string responseText;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
class BaoCurl {
|
|
17
|
+
public:
|
|
18
|
+
BaoCurl();
|
|
19
|
+
~BaoCurl();
|
|
20
|
+
void open(std::string, std::string);
|
|
21
|
+
void setRequestHeader(std::string, std::string);
|
|
22
|
+
void setRequestHeader(std::string);
|
|
23
|
+
void setRequestHeaders(std::string);
|
|
24
|
+
/*
|
|
25
|
+
* setProxy必须在open后 send前设置
|
|
26
|
+
* 在send后失效 需重新设置
|
|
27
|
+
*/
|
|
28
|
+
void setProxy(std::string);
|
|
29
|
+
void setProxy(std::string, std::string,
|
|
30
|
+
std::string
|
|
31
|
+
);
|
|
32
|
+
/*
|
|
33
|
+
* setTimeout必须在open后 send前设置
|
|
34
|
+
* 在send后失效 需重新设置
|
|
35
|
+
* 单位:秒 例子:setTimeout(10,10);
|
|
36
|
+
*/
|
|
37
|
+
void setTimeout(
|
|
38
|
+
int connectTime,
|
|
39
|
+
int sendTime
|
|
40
|
+
);
|
|
41
|
+
/*
|
|
42
|
+
* 设置单条Cookie
|
|
43
|
+
*/
|
|
44
|
+
void setCookie(std::string key, std::string value, std::string domain);
|
|
45
|
+
/*
|
|
46
|
+
* 移除单条Cookie
|
|
47
|
+
*/
|
|
48
|
+
void removeCookie(std::string key, std::string domain);
|
|
49
|
+
void send();
|
|
50
|
+
void send(std::string);
|
|
51
|
+
void sendByte(const char*,const int);
|
|
52
|
+
/*
|
|
53
|
+
* 重置Curl 此前的操作全部失效
|
|
54
|
+
*/
|
|
55
|
+
void reset();
|
|
56
|
+
|
|
57
|
+
std::string getCookies();
|
|
58
|
+
std::string getCookie(std::string key);
|
|
59
|
+
std::string getResponseHeaders() { return this->m_stream.header; };
|
|
60
|
+
std::string getResponseBody() { return this->m_stream.responseText; };
|
|
61
|
+
long getResponseStatus();
|
|
62
|
+
void setRedirect(bool isAllow);//重定向
|
|
63
|
+
void printInnerLogger();//打印内部日志
|
|
64
|
+
|
|
65
|
+
enum HttpVersion {
|
|
66
|
+
http1_1,
|
|
67
|
+
http2,
|
|
68
|
+
};
|
|
69
|
+
void setHttpVersion(HttpVersion);
|
|
70
|
+
private:
|
|
71
|
+
CURL* m_pCURL = NULL;
|
|
72
|
+
struct curl_slist* m_pHeaders = NULL;
|
|
73
|
+
std::string m_method = "GET";
|
|
74
|
+
struct Stream_st m_stream;
|
|
75
|
+
struct curl_slist* m_cookies = NULL;
|
|
76
|
+
bool m_bProxy = false;
|
|
77
|
+
bool m_bIsHttps = false;
|
|
78
|
+
|
|
79
|
+
void init();
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
#endif // !_CURL_H
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#***************************************************************************
|
|
2
|
+
# _ _ ____ _
|
|
3
|
+
# Project ___| | | | _ \| |
|
|
4
|
+
# / __| | | | |_) | |
|
|
5
|
+
# | (__| |_| | _ <| |___
|
|
6
|
+
# \___|\___/|_| \_\_____|
|
|
7
|
+
#
|
|
8
|
+
# Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
9
|
+
#
|
|
10
|
+
# This software is licensed as described in the file COPYING, which
|
|
11
|
+
# you should have received as part of this distribution. The terms
|
|
12
|
+
# are also available at https://curl.se/docs/copyright.html.
|
|
13
|
+
#
|
|
14
|
+
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
15
|
+
# copies of the Software, and permit persons to whom the Software is
|
|
16
|
+
# furnished to do so, under the terms of the COPYING file.
|
|
17
|
+
#
|
|
18
|
+
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
19
|
+
# KIND, either express or implied.
|
|
20
|
+
#
|
|
21
|
+
###########################################################################
|
|
22
|
+
pkginclude_HEADERS = \
|
|
23
|
+
curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \
|
|
24
|
+
typecheck-gcc.h system.h urlapi.h options.h
|
|
25
|
+
|
|
26
|
+
pkgincludedir= $(includedir)/curl
|
|
27
|
+
|
|
28
|
+
CHECKSRC = $(CS_$(V))
|
|
29
|
+
CS_0 = @echo " RUN " $@;
|
|
30
|
+
CS_1 =
|
|
31
|
+
CS_ = $(CS_0)
|
|
32
|
+
|
|
33
|
+
checksrc:
|
|
34
|
+
$(CHECKSRC)@PERL@ $(top_srcdir)/lib/checksrc.pl -D$(top_srcdir)/include/curl $(pkginclude_HEADERS)
|
|
35
|
+
|
|
36
|
+
if CURLDEBUG
|
|
37
|
+
# for debug builds, we scan the sources on all regular make invokes
|
|
38
|
+
all-local: checksrc
|
|
39
|
+
endif
|