Add parameters like timeout, buffer_size to ClientSession.

master
Chunting Gu 6 years ago
parent 64b3700675
commit 0f0f6fdf8e

@ -7,6 +7,12 @@
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,
const std::string& credentials) {
headers_.Set(headers::kAuthorization, type + " " + credentials);

@ -15,12 +15,17 @@ namespace webcc {
// session for each thread instead.
class ClientSession {
public:
ClientSession() {
InitHeaders();
}
explicit ClientSession(int timeout = 0, bool ssl_verify = true,
std::size_t buffer_size = 0);
~ClientSession() = default;
void set_timeout(int timeout) {
if (timeout > 0) {
timeout_ = timeout;
}
}
void set_ssl_verify(bool ssl_verify) {
ssl_verify_ = ssl_verify;
}
@ -29,12 +34,6 @@ public:
buffer_size_ = buffer_size;
}
void set_timeout(int timeout) {
if (timeout > 0) {
timeout_ = timeout;
}
}
void SetHeader(const std::string& key, const std::string& value) {
headers_.Set(key, value);
}
@ -100,15 +99,15 @@ private:
// Additional headers for each request.
Headers headers_;
// Timeout in seconds for receiving response.
int timeout_;
// Verify the certificate of the peer or not.
bool ssl_verify_ = true;
bool ssl_verify_;
// 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;
std::size_t buffer_size_;
// Pool for Keep-Alive client connections.
ClientPool pool_;

@ -87,7 +87,7 @@ void Connection::DoRead() {
void Connection::OnRead(boost::system::error_code ec, std::size_t length) {
if (ec) {
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) {
// The socket of this connection has been closed.
// This happens, e.g., when the server was stopped by a signal (Ctrl-C).

Loading…
Cancel
Save