Add comment to HttpClientSession about the usage in multi-thread scenario.
This commit is contained in:
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
using namespace webcc;
|
using namespace webcc;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if (defined(WIN32) || defined(_WIN64))
|
#if (defined(WIN32) || defined(_WIN64))
|
||||||
// You need to set environment variable SSL_CERT_FILE properly to enable
|
// You need to set environment variable SSL_CERT_FILE properly to enable
|
||||||
// SSL verification.
|
// SSL verification.
|
||||||
@@ -15,9 +13,6 @@ bool kSslVerify = false;
|
|||||||
bool kSslVerify = true;
|
bool kSslVerify = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
// Examples
|
|
||||||
|
|
||||||
void ExampleBasic() {
|
void ExampleBasic() {
|
||||||
webcc::HttpClientSession session;
|
webcc::HttpClientSession session;
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ static void SetHeaders(const std::vector<std::string>& headers,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponsePtr HttpClientSession::Get(const std::string& url,
|
HttpResponsePtr HttpClientSession::Get(
|
||||||
const std::vector<std::string>& parameters,
|
const std::string& url, const std::vector<std::string>& parameters,
|
||||||
const std::vector<std::string>& headers) {
|
const std::vector<std::string>& headers) {
|
||||||
HttpRequestBuilder builder{http::methods::kGet};
|
HttpRequestBuilder builder{http::methods::kGet};
|
||||||
builder.url(url);
|
builder.url(url);
|
||||||
|
|
||||||
@@ -53,9 +53,9 @@ HttpResponsePtr HttpClientSession::Get(const std::string& url,
|
|||||||
return Request(builder());
|
return Request(builder());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponsePtr HttpClientSession::Post(const std::string& url,
|
HttpResponsePtr HttpClientSession::Post(
|
||||||
std::string&& data, bool json,
|
const std::string& url, std::string&& data, bool json,
|
||||||
const std::vector<std::string>& headers) {
|
const std::vector<std::string>& headers) {
|
||||||
HttpRequestBuilder builder{http::methods::kPost};
|
HttpRequestBuilder builder{http::methods::kPost};
|
||||||
builder.url(url);
|
builder.url(url);
|
||||||
|
|
||||||
@@ -67,9 +67,9 @@ HttpResponsePtr HttpClientSession::Post(const std::string& url,
|
|||||||
return Request(builder());
|
return Request(builder());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponsePtr HttpClientSession::Put(const std::string& url,
|
HttpResponsePtr HttpClientSession::Put(
|
||||||
std::string&& data, bool json,
|
const std::string& url, std::string&& data, bool json,
|
||||||
const std::vector<std::string>& headers) {
|
const std::vector<std::string>& headers) {
|
||||||
HttpRequestBuilder builder{http::methods::kPut};
|
HttpRequestBuilder builder{http::methods::kPut};
|
||||||
builder.url(url);
|
builder.url(url);
|
||||||
|
|
||||||
@@ -81,8 +81,8 @@ HttpResponsePtr HttpClientSession::Put(const std::string& url,
|
|||||||
return Request(builder());
|
return Request(builder());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponsePtr HttpClientSession::Delete(const std::string& url,
|
HttpResponsePtr HttpClientSession::Delete(
|
||||||
const std::vector<std::string>& headers) {
|
const std::string& url, const std::vector<std::string>& headers) {
|
||||||
HttpRequestBuilder builder{http::methods::kDelete};
|
HttpRequestBuilder builder{http::methods::kDelete};
|
||||||
builder.url(url);
|
builder.url(url);
|
||||||
|
|
||||||
@@ -91,9 +91,9 @@ HttpResponsePtr HttpClientSession::Delete(const std::string& url,
|
|||||||
return Request(builder());
|
return Request(builder());
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpResponsePtr HttpClientSession::Patch(const std::string& url,
|
HttpResponsePtr HttpClientSession::Patch(
|
||||||
std::string&& data, bool json,
|
const std::string& url, std::string&& data, bool json,
|
||||||
const std::vector<std::string>& headers) {
|
const std::vector<std::string>& headers) {
|
||||||
HttpRequestBuilder builder{http::methods::kPatch};
|
HttpRequestBuilder builder{http::methods::kPatch};
|
||||||
builder.url(url);
|
builder.url(url);
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ void HttpClientSession::InitHeaders() {
|
|||||||
// probably have called the second one "zlib" instead to avoid confusion with
|
// probably have called the second one "zlib" instead to avoid confusion with
|
||||||
// the raw deflate compressed data format.
|
// the raw deflate compressed data format.
|
||||||
// Simply put, "deflate" is not recommended for HTTP 1.1 encoding.
|
// Simply put, "deflate" is not recommended for HTTP 1.1 encoding.
|
||||||
//
|
|
||||||
headers_.Set(kAcceptEncoding, "gzip, deflate");
|
headers_.Set(kAcceptEncoding, "gzip, deflate");
|
||||||
|
|
||||||
headers_.Set(kAccept, "*/*");
|
headers_.Set(kAccept, "*/*");
|
||||||
@@ -145,7 +145,7 @@ HttpResponsePtr HttpClientSession::Send(HttpRequestPtr request) {
|
|||||||
|
|
||||||
const HttpClientPool::Key key{request->url()};
|
const HttpClientPool::Key key{request->url()};
|
||||||
|
|
||||||
// Reuse a connection or not.
|
// Reuse a pooled connection.
|
||||||
bool reuse = false;
|
bool reuse = false;
|
||||||
|
|
||||||
HttpClientPtr client = pool_.Get(key);
|
HttpClientPtr client = pool_.Get(key);
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
|
|
||||||
namespace webcc {
|
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 {
|
class HttpClientSession {
|
||||||
public:
|
public:
|
||||||
HttpClientSession();
|
HttpClientSession();
|
||||||
|
|||||||
Reference in New Issue
Block a user