summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/lib/util/client_http.hpp12
-rw-r--r--src/lib/util/client_https.hpp2
-rw-r--r--src/lib/util/server_http.hpp11
3 files changed, 19 insertions, 6 deletions
diff --git a/src/lib/util/client_http.hpp b/src/lib/util/client_http.hpp
index df188090f87..63bd60c1f32 100644
--- a/src/lib/util/client_http.hpp
+++ b/src/lib/util/client_http.hpp
@@ -70,6 +70,8 @@ namespace webpp {
public:
/// Set timeout on requests in seconds. Default value: 0 (no timeout).
size_t timeout = 0;
+ /// Set connect timeout in seconds. Default value: 0 (Config::timeout is then used instead).
+ size_t timeout_connect=0;
/// Set proxy server (server:port)
std::string proxy_server;
};
@@ -213,12 +215,14 @@ namespace webpp {
virtual void connect()=0;
- std::shared_ptr<asio::system_timer> get_timeout_timer() {
- if (config.timeout == 0)
+ std::shared_ptr<asio::system_timer> get_timeout_timer(size_t timeout=0) {
+ if(timeout==0)
+ timeout=config.timeout;
+ if (timeout == 0)
return nullptr;
auto timer = std::make_shared<asio::system_timer>(io_context);
- timer->expires_from_now(std::chrono::seconds(config.timeout));
+ timer->expires_from_now(std::chrono::seconds(timeout));
timer->async_wait([this](const std::error_code& ec) {
if (!ec) {
close();
@@ -401,7 +405,7 @@ namespace webpp {
socket = std::make_unique<HTTP>(io_context);
}
- auto timer = get_timeout_timer();
+ auto timer = get_timeout_timer(config.timeout_connect);
asio::async_connect(*socket, it, [this,timer]
(const std::error_code &ec, asio::ip::tcp::resolver::iterator /*it*/){
if (timer)
diff --git a/src/lib/util/client_https.hpp b/src/lib/util/client_https.hpp
index fc1f12bb075..3300ea6865f 100644
--- a/src/lib/util/client_https.hpp
+++ b/src/lib/util/client_https.hpp
@@ -56,7 +56,7 @@ namespace webpp {
socket = std::make_unique<HTTPS>(io_context, m_context);
}
- auto timer = get_timeout_timer();
+ auto timer = get_timeout_timer(config.timeout_connect);
asio::async_connect(socket->lowest_layer(), it, [this, timer]
(const std::error_code &ec, asio::ip::tcp::resolver::iterator /*it*/) {
if (timer)
diff --git a/src/lib/util/server_http.hpp b/src/lib/util/server_http.hpp
index 57fd57e6993..978e9e3ce40 100644
--- a/src/lib/util/server_http.hpp
+++ b/src/lib/util/server_http.hpp
@@ -89,6 +89,12 @@ namespace webpp {
void send(std::string str) { m_ostream << m_header.str() << "Content-Length: " << str.length() << "\r\n\r\n" << str; }
size_t size() const { return m_streambuf.size(); }
std::shared_ptr<socket_type> socket() { return m_socket; }
+
+ /// If true, force server to close the connection after the response have been sent.
+ ///
+ /// This is useful when implementing a HTTP/1.0-server sending content
+ /// without specifying the content length.
+ bool close_connection_after_response = false;
};
class Content : public std::istream {
@@ -182,7 +188,7 @@ namespace webpp {
void remove_handler(std::string regex)
{
std::lock_guard<std::mutex> lock(m_resource_mutex);
- for (auto &it = m_resource.begin(); it != m_resource.end(); ++it)
+ for (auto it = m_resource.begin(); it != m_resource.end(); ++it)
{
if (it->first.getstr() == regex)
{
@@ -428,6 +434,9 @@ namespace webpp {
return;
}
+ if (response->close_connection_after_response)
+ return;
+
auto range = request->header.equal_range("Connection");
case_insensitive_equals check;
for (auto it = range.first; it != range.second; ++it) {