Add comment to HttpClientSession about the usage in multi-thread scenario.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ static void SetHeaders(const std::vector<std::string>& headers,
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponsePtr HttpClientSession::Get(const std::string& url,
|
||||
const std::vector<std::string>& parameters,
|
||||
HttpResponsePtr HttpClientSession::Get(
|
||||
const std::string& url, const std::vector<std::string>& parameters,
|
||||
const std::vector<std::string>& headers) {
|
||||
HttpRequestBuilder builder{http::methods::kGet};
|
||||
builder.url(url);
|
||||
@@ -53,8 +53,8 @@ HttpResponsePtr HttpClientSession::Get(const std::string& url,
|
||||
return Request(builder());
|
||||
}
|
||||
|
||||
HttpResponsePtr HttpClientSession::Post(const std::string& url,
|
||||
std::string&& data, bool json,
|
||||
HttpResponsePtr HttpClientSession::Post(
|
||||
const std::string& url, std::string&& data, bool json,
|
||||
const std::vector<std::string>& headers) {
|
||||
HttpRequestBuilder builder{http::methods::kPost};
|
||||
builder.url(url);
|
||||
@@ -67,8 +67,8 @@ HttpResponsePtr HttpClientSession::Post(const std::string& url,
|
||||
return Request(builder());
|
||||
}
|
||||
|
||||
HttpResponsePtr HttpClientSession::Put(const std::string& url,
|
||||
std::string&& data, bool json,
|
||||
HttpResponsePtr HttpClientSession::Put(
|
||||
const std::string& url, std::string&& data, bool json,
|
||||
const std::vector<std::string>& 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<std::string>& headers) {
|
||||
HttpResponsePtr HttpClientSession::Delete(
|
||||
const std::string& url, const std::vector<std::string>& headers) {
|
||||
HttpRequestBuilder builder{http::methods::kDelete};
|
||||
builder.url(url);
|
||||
|
||||
@@ -91,8 +91,8 @@ HttpResponsePtr HttpClientSession::Delete(const std::string& url,
|
||||
return Request(builder());
|
||||
}
|
||||
|
||||
HttpResponsePtr HttpClientSession::Patch(const std::string& url,
|
||||
std::string&& data, bool json,
|
||||
HttpResponsePtr HttpClientSession::Patch(
|
||||
const std::string& url, std::string&& data, bool json,
|
||||
const std::vector<std::string>& 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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user