Add keep_alive() to HttpClientArgs

This commit is contained in:
Chunting Gu
2019-03-19 16:38:29 +08:00
parent 5853f39ac3
commit f6c305d266
3 changed files with 15 additions and 3 deletions
+5
View File
@@ -71,6 +71,11 @@ HttpResponsePtr HttpClientSession::Request(HttpRequestArgs&& args) {
std::move(args.headers_[i]));
}
// No keep-alive?
if (!args.keep_alive_) {
request.SetHeader(http::headers::kConnection, "Close");
}
request.Prepare();
bool ssl_verify = GetSslVerify(ssl_verify_, args.ssl_verify_);
+9 -1
View File
@@ -19,7 +19,7 @@ class HttpClientSession;
class HttpRequestArgs {
public:
explicit HttpRequestArgs(const std::string& method = "")
: method_(method), json_(false), buffer_size_(0) {
: method_(method), json_(false), buffer_size_(0), keep_alive_(true) {
}
HttpRequestArgs(const HttpRequestArgs&) = default;
@@ -83,6 +83,11 @@ public:
return std::move(*this);
}
HttpRequestArgs&& keep_alive(bool keep_alive) {
keep_alive_ = keep_alive;
return std::move(*this);
}
private:
friend class HttpClientSession;
@@ -108,6 +113,9 @@ private:
// Size of the buffer to read response.
// Leave it to 0 for using default value.
std::size_t buffer_size_;
// Persistent connection.
bool keep_alive_;
};
} // namespace webcc