Add parameters like timeout, buffer_size to ClientSession.
This commit is contained in:
@@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
namespace webcc {
|
namespace webcc {
|
||||||
|
|
||||||
|
ClientSession::ClientSession(int timeout, bool ssl_verify,
|
||||||
|
std::size_t buffer_size)
|
||||||
|
: timeout_(timeout), ssl_verify_(ssl_verify), buffer_size_(buffer_size) {
|
||||||
|
InitHeaders();
|
||||||
|
}
|
||||||
|
|
||||||
void ClientSession::Auth(const std::string& type,
|
void ClientSession::Auth(const std::string& type,
|
||||||
const std::string& credentials) {
|
const std::string& credentials) {
|
||||||
headers_.Set(headers::kAuthorization, type + " " + credentials);
|
headers_.Set(headers::kAuthorization, type + " " + credentials);
|
||||||
|
|||||||
+13
-14
@@ -15,12 +15,17 @@ namespace webcc {
|
|||||||
// session for each thread instead.
|
// session for each thread instead.
|
||||||
class ClientSession {
|
class ClientSession {
|
||||||
public:
|
public:
|
||||||
ClientSession() {
|
explicit ClientSession(int timeout = 0, bool ssl_verify = true,
|
||||||
InitHeaders();
|
std::size_t buffer_size = 0);
|
||||||
}
|
|
||||||
|
|
||||||
~ClientSession() = default;
|
~ClientSession() = default;
|
||||||
|
|
||||||
|
void set_timeout(int timeout) {
|
||||||
|
if (timeout > 0) {
|
||||||
|
timeout_ = timeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void set_ssl_verify(bool ssl_verify) {
|
void set_ssl_verify(bool ssl_verify) {
|
||||||
ssl_verify_ = ssl_verify;
|
ssl_verify_ = ssl_verify;
|
||||||
}
|
}
|
||||||
@@ -29,12 +34,6 @@ public:
|
|||||||
buffer_size_ = buffer_size;
|
buffer_size_ = buffer_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_timeout(int timeout) {
|
|
||||||
if (timeout > 0) {
|
|
||||||
timeout_ = timeout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetHeader(const std::string& key, const std::string& value) {
|
void SetHeader(const std::string& key, const std::string& value) {
|
||||||
headers_.Set(key, value);
|
headers_.Set(key, value);
|
||||||
}
|
}
|
||||||
@@ -100,15 +99,15 @@ private:
|
|||||||
// Additional headers for each request.
|
// Additional headers for each request.
|
||||||
Headers headers_;
|
Headers headers_;
|
||||||
|
|
||||||
|
// Timeout in seconds for receiving response.
|
||||||
|
int timeout_;
|
||||||
|
|
||||||
// Verify the certificate of the peer or not.
|
// Verify the certificate of the peer or not.
|
||||||
bool ssl_verify_ = true;
|
bool ssl_verify_;
|
||||||
|
|
||||||
// The size of the buffer for reading response.
|
// The size of the buffer for reading response.
|
||||||
// 0 means default value will be used.
|
// 0 means default value will be used.
|
||||||
std::size_t buffer_size_ = 0;
|
std::size_t buffer_size_;
|
||||||
|
|
||||||
// Timeout in seconds for receiving response.
|
|
||||||
int timeout_ = 0;
|
|
||||||
|
|
||||||
// Pool for Keep-Alive client connections.
|
// Pool for Keep-Alive client connections.
|
||||||
ClientPool pool_;
|
ClientPool pool_;
|
||||||
|
|||||||
+1
-1
@@ -87,7 +87,7 @@ void Connection::DoRead() {
|
|||||||
void Connection::OnRead(boost::system::error_code ec, std::size_t length) {
|
void Connection::OnRead(boost::system::error_code ec, std::size_t length) {
|
||||||
if (ec) {
|
if (ec) {
|
||||||
if (ec == boost::asio::error::eof) {
|
if (ec == boost::asio::error::eof) {
|
||||||
LOG_WARN("Socket read EOF (%s).", ec.message().c_str());
|
LOG_INFO("Socket read EOF (%s).", ec.message().c_str());
|
||||||
} else if (ec == boost::asio::error::operation_aborted) {
|
} else if (ec == boost::asio::error::operation_aborted) {
|
||||||
// The socket of this connection has been closed.
|
// The socket of this connection has been closed.
|
||||||
// This happens, e.g., when the server was stopped by a signal (Ctrl-C).
|
// This happens, e.g., when the server was stopped by a signal (Ctrl-C).
|
||||||
|
|||||||
Reference in New Issue
Block a user