move constructing MlValues to clib from interpreter

This commit is contained in:
2021-02-14 08:56:14 +01:00
parent 2e58a31266
commit 8f0b19798f
3 changed files with 58 additions and 11 deletions

View File

@@ -20,9 +20,6 @@
HttpClient::HttpClient(){};
std::pair<int, std::string> HttpClient::doGetRequest(const std::string &url, const std::unordered_map<std::string, std::string> &headers) {
// ^(?:((?:https?|s?ftp):)\/\/)([^:\/\s]+)(?::(\d*))?(?:\/([^\s?#]+)?([?][^?#]*)?(#.*)?)?
// viz test
// https://api.iextrading.com:443/1.0/stock/market/batch?symbols=cah,khc,syf,jnj&types=quote#muhehe
// https://stackoverflow.com/questions/25896916/parse-http-headers-in-c
std::regex rgx{R"(^(?:((?:https?|s?ftp):)//)([^:/\s]+)(?::(\d*))?(?:/([^\s?#]+)?([?][^?#]*)?(#.*)?)?)"};
@@ -56,15 +53,17 @@ std::pair<int, std::string> HttpClient::doGetRequest(const std::string &url, con
// std::cout << i << ": '" << matches[i].str() << "'\n";
}
} else {
std::cerr << "Match not found\n"; // TODO better message
std::cerr << "Match not found" << std::endl; // TODO better message
}
std::string headers_string = "";
for (auto it = headers.begin(); it != headers.end(); ++it) {
headers_string.append("\r\n" + it->first + ": " + it->second);
// std::cerr << "KEY: `" << it->first << "`, VALUE: `" << it->second << '`' << std::endl;
}
std::string request = "GET " + full_url + " HTTP/1.0\r\nHost: " + server + headers_string + "\r\n\r\n";
std::string request = "GET " + full_url + " HTTP/1.0\r\nHost: " + server + headers_string + "\r\n\r\n";
// TODO memory leaks ???
int bytes_read = sslRequest(server, request);
@@ -107,10 +106,6 @@ std::pair<int, std::string> HttpClient::doGetRequest(const std::string &url, con
}
}
// for(auto& kv: headers_map) {
// std::cout << "KEY: `" << kv.first << "`, VALUE: `" << kv.second << '`' << std::endl;
// }
// TODO if error return error desc in string
return std::make_pair(200, body);
};
@@ -135,8 +130,10 @@ int HttpClient::sslRecvPacket() {
char buf[len + 1];
do {
len = SSL_read(ssl, buf, len);
buf[len] = 0;
ssl_read_packet.append((const char *)buf);
if (len >= 0) {
buf[len] = 0;
ssl_read_packet.append((const char *)buf);
}
} while (len > 0);
if (len < 0) {
@@ -224,6 +221,7 @@ int HttpClient::sslRequest(const std::string &server_name, const std::string &re
// printf ("SSL connection using %s\n", SSL_get_cipher (ssl));
// send request
//std::err << request << std::endl;
sslSendPacket(request);
// read response and return its length