Skip to content
Permalink
Browse files

http: close connection if server requests

  • Loading branch information...
binarytrails authored and aberaud committed Oct 7, 2019
1 parent 347f404 commit d77c868c55882642be9fa3a13ead494e1e5ac8e8
Showing with 13 additions and 0 deletions.
  1. +13 −0 src/http.cpp
@@ -31,6 +31,7 @@ namespace http {

constexpr char HTTP_HEADER_CONNECTION[] = "Connection";
constexpr char HTTP_HEADER_CONNECTION_KEEP_ALIVE[] = "keep-alive";
constexpr char HTTP_HEADER_CONNECTION_CLOSE[] = "close";
constexpr char HTTP_HEADER_CONTENT_LENGTH[] = "Content-Length";
constexpr char HTTP_HEADER_CONTENT_TYPE[] = "Content-Type";
constexpr char HTTP_HEADER_CONTENT_TYPE_JSON[] = "application/json";
@@ -927,6 +928,12 @@ Request::handle_response_header(const asio::error_code& ec)
conn_->async_read_until(BODY_VALUE_DELIM,
std::bind(&Request::handle_response_body, this, std::placeholders::_1, std::placeholders::_2));
}
// server wants to close the connection
else if (connection_it != response_.headers.end() and connection_it->second == HTTP_HEADER_CONNECTION_CLOSE)
{
terminate(asio::error::eof);
}
// client wants to close the connection
else if (connection_type_ == restinio::http_connection_header_t::close)
{
terminate(asio::error::eof);
@@ -1004,6 +1011,12 @@ Request::handle_response_body(const asio::error_code& ec, const size_t bytes)
conn_->async_read_until(BODY_VALUE_DELIM,
std::bind(&Request::handle_response_body, this, std::placeholders::_1, std::placeholders::_2));
}
// server wants to close the connection
else if (connection_it != response_.headers.end() and connection_it->second == HTTP_HEADER_CONNECTION_CLOSE)
{
terminate(asio::error::eof);
}
// client wants to close the connection
else if (connection_type_ == restinio::http_connection_header_t::close)
{
terminate(asio::error::eof);

0 comments on commit d77c868

Please sign in to comment.
You can’t perform that action at this time.