diff --git a/examples/http_client.cc b/examples/http_client.cc index 9f4d55d..52dd807 100644 --- a/examples/http_client.cc +++ b/examples/http_client.cc @@ -5,8 +5,6 @@ using namespace webcc; -// ----------------------------------------------------------------------------- - #if (defined(WIN32) || defined(_WIN64)) // You need to set environment variable SSL_CERT_FILE properly to enable // SSL verification. @@ -15,9 +13,6 @@ bool kSslVerify = false; bool kSslVerify = true; #endif -// ----------------------------------------------------------------------------- -// Examples - void ExampleBasic() { webcc::HttpClientSession session; diff --git a/webcc/http_client_session.cc b/webcc/http_client_session.cc index c81ba9e..bf5ecc3 100644 --- a/webcc/http_client_session.cc +++ b/webcc/http_client_session.cc @@ -37,9 +37,9 @@ static void SetHeaders(const std::vector& headers, } } -HttpResponsePtr HttpClientSession::Get(const std::string& url, - const std::vector& parameters, - const std::vector& headers) { +HttpResponsePtr HttpClientSession::Get( + const std::string& url, const std::vector& parameters, + const std::vector& headers) { HttpRequestBuilder builder{http::methods::kGet}; builder.url(url); @@ -53,9 +53,9 @@ HttpResponsePtr HttpClientSession::Get(const std::string& url, return Request(builder()); } -HttpResponsePtr HttpClientSession::Post(const std::string& url, - std::string&& data, bool json, - const std::vector& headers) { +HttpResponsePtr HttpClientSession::Post( + const std::string& url, std::string&& data, bool json, + const std::vector& headers) { HttpRequestBuilder builder{http::methods::kPost}; builder.url(url); @@ -67,9 +67,9 @@ HttpResponsePtr HttpClientSession::Post(const std::string& url, return Request(builder()); } -HttpResponsePtr HttpClientSession::Put(const std::string& url, - std::string&& data, bool json, - const std::vector& headers) { +HttpResponsePtr HttpClientSession::Put( + const std::string& url, std::string&& data, bool json, + const std::vector& headers) { HttpRequestBuilder builder{http::methods::kPut}; builder.url(url); @@ -81,8 +81,8 @@ HttpResponsePtr HttpClientSession::Put(const std::string& url, return Request(builder()); } -HttpResponsePtr HttpClientSession::Delete(const std::string& url, - const std::vector& headers) { +HttpResponsePtr HttpClientSession::Delete( + const std::string& url, const std::vector& headers) { HttpRequestBuilder builder{http::methods::kDelete}; builder.url(url); @@ -91,9 +91,9 @@ HttpResponsePtr HttpClientSession::Delete(const std::string& url, return Request(builder()); } -HttpResponsePtr HttpClientSession::Patch(const std::string& url, - std::string&& data, bool json, - const std::vector& headers) { +HttpResponsePtr HttpClientSession::Patch( + const std::string& url, std::string&& data, bool json, + const std::vector& headers) { HttpRequestBuilder builder{http::methods::kPatch}; builder.url(url); @@ -130,7 +130,7 @@ void HttpClientSession::InitHeaders() { // probably have called the second one "zlib" instead to avoid confusion with // the raw deflate compressed data format. // Simply put, "deflate" is not recommended for HTTP 1.1 encoding. - // + headers_.Set(kAcceptEncoding, "gzip, deflate"); headers_.Set(kAccept, "*/*"); @@ -145,7 +145,7 @@ HttpResponsePtr HttpClientSession::Send(HttpRequestPtr request) { const HttpClientPool::Key key{request->url()}; - // Reuse a connection or not. + // Reuse a pooled connection. bool reuse = false; HttpClientPtr client = pool_.Get(key); diff --git a/webcc/http_client_session.h b/webcc/http_client_session.h index 4cad2c0..5180146 100644 --- a/webcc/http_client_session.h +++ b/webcc/http_client_session.h @@ -13,6 +13,10 @@ namespace webcc { +// HTTP requests session providing connection-pooling, configuration and more. +// NOTE: +// A session shouldn't be shared by multiple threads. Please create a new +// session for each thread instead. class HttpClientSession { public: HttpClientSession();