Merge HttpClient and HttpSslClient; draft of client connection pool.
This commit is contained in:
+91
-10
@@ -3,23 +3,37 @@
|
||||
#include "webcc/http_client_session.h"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
void GetBoostOrgLicense(webcc::HttpClientSession& session) {
|
||||
auto r = session.Get("https://www.boost.org/LICENSE_1_0.txt");
|
||||
using namespace webcc;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#if (defined(WIN32) || defined(_WIN64))
|
||||
// You need to set environment variable SSL_CERT_FILE properly to enable
|
||||
// SSL verification.
|
||||
bool kSslVerify = false;
|
||||
#else
|
||||
bool kSslVerify = true;
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void GetBoostOrgLicense(HttpClientSession& session) {
|
||||
try {
|
||||
auto r = session.Request(HttpRequestArgs{ "GET" }.
|
||||
url("https://www.boost.org/LICENSE_1_0.txt").
|
||||
ssl_verify(kSslVerify));
|
||||
|
||||
if (r) {
|
||||
std::cout << r->content() << std::endl;
|
||||
|
||||
} catch (const webcc::Exception& e) {
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||
|
||||
using namespace webcc;
|
||||
|
||||
// TODO
|
||||
void Test(HttpClientSession& session) {
|
||||
HttpResponsePtr r;
|
||||
|
||||
HttpClientSession session;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
r = session.Request(HttpRequestArgs{ "GET" }.
|
||||
@@ -66,6 +80,73 @@ int main() {
|
||||
} catch (const webcc::Exception& e) {
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void TestKeepAlive1(HttpClientSession& session) {
|
||||
try {
|
||||
auto r = session.Request(HttpRequestArgs{ "GET" }.
|
||||
url("http://httpbin.org/get").
|
||||
parameters({ "key1", "value1", "key2", "value2" }).
|
||||
headers({ "Accept", "application/json" }).
|
||||
buffer_size(1000));
|
||||
|
||||
std::cout << r->content() << std::endl;
|
||||
|
||||
} catch (const Exception& e) {
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void TestKeepAlive2(HttpClientSession& session) {
|
||||
try {
|
||||
auto r = session.Request(webcc::HttpRequestArgs("GET").
|
||||
url("https://api.github.com/events").
|
||||
ssl_verify(false).buffer_size(1500));
|
||||
|
||||
//std::cout << r->content() << std::endl;
|
||||
|
||||
} catch (const Exception& e) {
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void TestKeepAlive3(HttpClientSession& session) {
|
||||
try {
|
||||
auto r = session.Request(webcc::HttpRequestArgs("GET").
|
||||
url("https://www.boost.org/LICENSE_1_0.txt").
|
||||
ssl_verify(false));
|
||||
|
||||
//std::cout << r->content() << std::endl;
|
||||
|
||||
} catch (const Exception& e) {
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void TestKeepAlive4(HttpClientSession& session) {
|
||||
try {
|
||||
auto r = session.Request(webcc::HttpRequestArgs("GET").
|
||||
url("https://www.google.com").
|
||||
ssl_verify(false));
|
||||
|
||||
//std::cout << r->content() << std::endl;
|
||||
|
||||
} catch (const Exception& e) {
|
||||
std::cout << "Exception: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
int main() {
|
||||
WEBCC_LOG_INIT("", LOG_CONSOLE);
|
||||
|
||||
HttpClientSession session;
|
||||
|
||||
GetBoostOrgLicense(session);
|
||||
|
||||
//TestKeepAlive1(session);
|
||||
//TestKeepAlive1(session);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user