33extern sol::state Lua;
44
55std::vector<RemoteRequest> Remote::s_Container = {};
6+ std::string Remote::certificates = " " ;
7+
8+ bool Remote::setSSLCerts (const std::string& bundle)
9+ {
10+ certificates.assign (bundle);
11+ return true ;
12+ }
613
714/* ** Lua ***/
815sol::table Remote::fetchHTTP (const std::string& url, sol::table params, sol::table auth)
916{
1017 cpr::Parameters cprParams = GetParameters (params);
1118 cpr::Authentication cprAuth = GetAuthentication (auth);
1219
20+ cpr::ssl::CaInfo Certs (certificates.c_str ());
21+ cpr::SslOptions opts;
22+ opts.SetOption (Certs);
23+
1324 cpr::Response r = cpr::Get (
1425 cpr::Url (url),
1526 cprParams,
16- cprAuth
27+ cprAuth,
28+ opts
1729 );
1830
1931 sol::table resultTable = Lua.create_table ();
@@ -27,9 +39,13 @@ sol::table Remote::fetchHTTP(const std::string& url, sol::table params, sol::tab
2739
2840void Remote::fetchHTTPAsync (sol::function handler, const std::string& url, sol::table params, sol::table auth)
2941{
42+ cpr::ssl::CaInfo Certs (certificates.c_str ());
43+ cpr::SslOptions opts;
44+ opts.SetOption (Certs);
45+
3046 cpr::Parameters cprParams = GetParameters (params);
3147 cpr::Authentication cprAuth = GetAuthentication (auth);
32- s_Container.emplace_back (handler, RemoteRequestType::GET, url, cprParams, cpr::Header{}, cpr::Body (" " ), cpr::Payload{}, cprAuth);
48+ s_Container.emplace_back (handler, RemoteRequestType::GET, url, cprParams, cpr::Header{}, cpr::Body (" " ), cpr::Payload{}, cprAuth, opts );
3349}
3450
3551sol::table Remote::postHTTP (const std::string& url, sol::table data)
@@ -65,12 +81,17 @@ sol::table Remote::postHTTP(const std::string& url, sol::table data)
6581 }
6682 }
6783
84+ cpr::ssl::CaInfo Certs (certificates.c_str ());
85+ cpr::SslOptions opts;
86+ opts.SetOption (Certs);
87+
6888 cpr::Response r = cpr::Post (
6989 cpr::Url (url),
7090 cprHeader,
7191 cprBody,
7292 cprParams,
73- cprPayload
93+ cprPayload,
94+ opts
7495 );
7596
7697 sol::table resultTable = Lua.create_table ();
@@ -115,7 +136,11 @@ void Remote::postHTTPAsync(sol::function handler, const std::string& url, sol::t
115136 }
116137 }
117138
118- s_Container.emplace_back (handler, RemoteRequestType::POST, url, cprParams, cprHeader, cprBody, cprPayload, cpr::Authentication (" " , " " ));
139+ cpr::ssl::CaInfo Certs (certificates.c_str ());
140+ cpr::SslOptions opts;
141+ opts.SetOption (Certs);
142+
143+ s_Container.emplace_back (handler, RemoteRequestType::POST, url, cprParams, cprHeader, cprBody, cprPayload, cpr::Authentication (" " , " " ), opts);
119144}
120145
121146/* ** Internal ***/
@@ -125,6 +150,7 @@ void Remote::Init(sol::state* Lua)
125150
126151 sol::usertype<Remote> userdata = Lua->new_usertype <Remote>(" Remote" );
127152
153+ userdata[" setSSLCerts" ] = &Remote::setSSLCerts;
128154 userdata[" fetch" ] = sol::overload (&Remote::fetchHTTP, &Remote::fetchHTTPAsync);
129155 userdata[" post" ] = sol::overload (&Remote::postHTTP, &Remote::postHTTPAsync);
130156}
0 commit comments