Allow to set buffer size for client; don't auto adjust reading buffer size; refine the global definitions.

This commit is contained in:
Chunting Gu
2019-02-11 12:46:27 +08:00
parent ae9d4efcf1
commit 3e60c76da1
47 changed files with 559 additions and 423 deletions
+38 -3
View File
@@ -5,6 +5,11 @@
#include "webcc/rest_ssl_client.h"
#include "webcc/logger.h"
const bool kSslVerify = false;
#define PRINT_CONTENT 0
static Json::Value StringToJson(const std::string& str) {
Json::Value json;
@@ -18,10 +23,11 @@ static Json::Value StringToJson(const std::string& str) {
return json;
}
void Test() {
webcc::RestSslClient client("api.github.com");
void ListPublicEvents() {
webcc::RestSslClient client("api.github.com", "", kSslVerify);
if (client.Get("/events")) {
#if PRINT_CONTENT
Json::Value json = StringToJson(client.response()->content());
// Pretty print the JSON.
@@ -33,6 +39,33 @@ void Test() {
writer->write(json, &std::cout);
std::cout << std::endl;
#endif // PRINT_CONTENT
} else {
std::cout << webcc::DescribeError(client.error());
if (client.timed_out()) {
std::cout << " (timed out)";
}
std::cout << std::endl;
}
}
void ListUserFollowers() {
webcc::RestSslClient client("api.github.com", "", kSslVerify);
if (client.Get("/users/sprinfall/followers")) {
#if PRINT_CONTENT
Json::Value json = StringToJson(client.response()->content());
// Pretty print the JSON.
Json::StreamWriterBuilder builder;
builder["indentation"] = " ";
std::unique_ptr<Json::StreamWriter> writer(builder.newStreamWriter());
writer->write(json, &std::cout);
std::cout << std::endl;
#endif // PRINT_CONTENT
} else {
std::cout << webcc::DescribeError(client.error());
if (client.timed_out()) {
@@ -45,7 +78,9 @@ void Test() {
int main() {
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
Test();
//ListPublicEvents();
ListUserFollowers();
return 0;
}