Add timeout setting HttpClientSession.

This commit is contained in:
Chunting Gu
2019-03-19 12:37:15 +08:00
parent 53fb2a92c9
commit 3566b1d98b
2 changed files with 17 additions and 6 deletions
+2
View File
@@ -92,6 +92,8 @@ HttpResponsePtr HttpClientSession::Request(HttpRequestArgs&& args) {
LOG_VERB("Reuse an existing connection.");
}
client->set_timeout(timeout_);
if (!client->Request(request, !reuse)) {
throw Exception(client->error(), client->timed_out());
}
+15 -6
View File
@@ -27,10 +27,6 @@ public:
charset_ = charset;
}
void AddHeader(const std::string& key, const std::string& value) {
headers_.Add(key, value);
}
void set_ssl_verify(bool ssl_verify) {
ssl_verify_.emplace(ssl_verify);
}
@@ -39,6 +35,16 @@ public:
buffer_size_ = buffer_size;
}
void set_timeout(int timeout) {
if (timeout > 0) {
timeout_ = timeout;
}
}
void AddHeader(const std::string& key, const std::string& value) {
headers_.Add(key, value);
}
HttpResponsePtr Request(HttpRequestArgs&& args);
HttpResponsePtr Get(const std::string& url,
@@ -68,16 +74,19 @@ private:
// E.g., "utf-8".
std::string charset_;
// Headers for each request sent from this session.
// Additional headers for each request.
HttpHeaderDict headers_;
// Verify the certificate of the peer or not.
boost::optional<bool> ssl_verify_;
// The bytes of the buffer for reading response.
// The size of the buffer for reading response.
// 0 means default value will be used.
std::size_t buffer_size_ = 0;
// Timeout in seconds for receiving response.
int timeout_ = 0;
// Connection pool for keep-alive.
HttpClientPool pool_;
};