Feature/http async (#90)

* unittest working / uses shared_ptr for a bunch of things 🗿

* fix command line tools

* fix ws + add doc

* add more logging
This commit is contained in:
Benjamin Sergeant
2019-06-05 17:04:24 -07:00
committed by GitHub
parent 012193c74e
commit 78b3d7ff2d
14 changed files with 490 additions and 223 deletions

View File

@ -95,19 +95,20 @@ namespace ix
const std::string& output,
bool compress)
{
HttpRequestArgs args;
args.extraHeaders = parseHeaders(headersData);
args.connectTimeout = connectTimeout;
args.transferTimeout = transferTimeout;
args.followRedirects = followRedirects;
args.maxRedirects = maxRedirects;
args.verbose = verbose;
args.compress = compress;
args.logger = [](const std::string& msg)
HttpClient httpClient;
auto args = httpClient.createRequest();
args->extraHeaders = parseHeaders(headersData);
args->connectTimeout = connectTimeout;
args->transferTimeout = transferTimeout;
args->followRedirects = followRedirects;
args->maxRedirects = maxRedirects;
args->verbose = verbose;
args->compress = compress;
args->logger = [](const std::string& msg)
{
std::cout << msg;
};
args.onProgressCallback = [](int current, int total) -> bool
args->onProgressCallback = [](int current, int total) -> bool
{
std::cerr << "\r" << "Downloaded "
<< current << " bytes out of " << total;
@ -116,8 +117,7 @@ namespace ix
HttpParameters httpParameters = parsePostParameters(data);
HttpClient httpClient;
HttpResponse response;
HttpResponsePtr response;
if (headersOnly)
{
response = httpClient.head(url, args);
@ -133,21 +133,21 @@ namespace ix
std::cerr << std::endl;
for (auto it : response.headers)
for (auto it : response->headers)
{
std::cerr << it.first << ": " << it.second << std::endl;
}
std::cerr << "Upload size: " << response.uploadSize << std::endl;
std::cerr << "Download size: " << response.downloadSize << std::endl;
std::cerr << "Upload size: " << response->uploadSize << std::endl;
std::cerr << "Download size: " << response->downloadSize << std::endl;
std::cerr << "Status: " << response.statusCode << std::endl;
if (response.errorCode != HttpErrorCode::Ok)
std::cerr << "Status: " << response->statusCode << std::endl;
if (response->errorCode != HttpErrorCode::Ok)
{
std::cerr << "error message: " << response.errorMsg << std::endl;
std::cerr << "error message: " << response->errorMsg << std::endl;
}
if (!headersOnly && response.errorCode == HttpErrorCode::Ok)
if (!headersOnly && response->errorCode == HttpErrorCode::Ok)
{
if (save || !output.empty())
{
@ -160,14 +160,14 @@ namespace ix
std::cout << "Writing to disk: " << filename << std::endl;
std::ofstream out(filename);
out.write((char*)&response.payload.front(), response.payload.size());
out.write((char*)&response->payload.front(), response->payload.size());
out.close();
}
else
{
if (response.headers["Content-Type"] != "application/octet-stream")
if (response->headers["Content-Type"] != "application/octet-stream")
{
std::cout << "payload: " << response.payload << std::endl;
std::cout << "payload: " << response->payload << std::endl;
}
else
{