Refine keep-alive connections.

This commit is contained in:
Chunting Gu
2019-03-12 17:39:15 +08:00
parent 901b2902a2
commit 5abd7e275c
19 changed files with 278 additions and 147 deletions
+20 -21
View File
@@ -1,4 +1,5 @@
#include <iostream>
#include <thread>
#include "webcc/http_client_session.h"
#include "webcc/logger.h"
@@ -82,29 +83,11 @@ void Test(HttpClientSession& session) {
}
}
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;
}
@@ -138,15 +121,31 @@ void TestKeepAlive4(HttpClientSession& session) {
// -----------------------------------------------------------------------------
void Sleep(int seconds) {
if (seconds > 0) {
LOG_INFO("Sleep %d seconds...", seconds);
std::this_thread::sleep_for(std::chrono::seconds(seconds));
}
}
int main() {
WEBCC_LOG_INIT("", LOG_CONSOLE);
HttpClientSession session;
GetBoostOrgLicense(session);
// TEST keep-alive.
//TestKeepAlive1(session);
//TestKeepAlive1(session);
try {
// Keep-Alive by default
session.Get("http://httpbin.org/get");
session.Get("http://httpbin.org/get", {}, { "Connection", "Close" });
session.Get("http://httpbin.org/get");
} catch (const Exception& e) {
std::cout << "Exception: " << e.what() << std::endl;
}
return 0;
}
+1 -1
View File
@@ -9,7 +9,7 @@ public:
~CalcService() override = default;
bool Handle(const webcc::SoapRequest& soap_request,
webcc::SoapResponse* soap_response) override;
webcc::SoapResponse* soap_response) final;
};
#endif // CALC_SERVICE_H_