Skip to content

Commit

Permalink
http: close connection if server requests
Browse files Browse the repository at this point in the history
  • Loading branch information
binarytrails authored and aberaud committed Oct 7, 2019
1 parent 347f404 commit d77c868
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/http.cpp
Expand Up @@ -31,6 +31,7 @@ namespace http {


constexpr char HTTP_HEADER_CONNECTION[] = "Connection"; constexpr char HTTP_HEADER_CONNECTION[] = "Connection";
constexpr char HTTP_HEADER_CONNECTION_KEEP_ALIVE[] = "keep-alive"; 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_LENGTH[] = "Content-Length";
constexpr char HTTP_HEADER_CONTENT_TYPE[] = "Content-Type"; constexpr char HTTP_HEADER_CONTENT_TYPE[] = "Content-Type";
constexpr char HTTP_HEADER_CONTENT_TYPE_JSON[] = "application/json"; constexpr char HTTP_HEADER_CONTENT_TYPE_JSON[] = "application/json";
Expand Down Expand Up @@ -927,6 +928,12 @@ Request::handle_response_header(const asio::error_code& ec)
conn_->async_read_until(BODY_VALUE_DELIM, conn_->async_read_until(BODY_VALUE_DELIM,
std::bind(&Request::handle_response_body, this, std::placeholders::_1, std::placeholders::_2)); 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) else if (connection_type_ == restinio::http_connection_header_t::close)
{ {
terminate(asio::error::eof); terminate(asio::error::eof);
Expand Down Expand Up @@ -1004,6 +1011,12 @@ Request::handle_response_body(const asio::error_code& ec, const size_t bytes)
conn_->async_read_until(BODY_VALUE_DELIM, conn_->async_read_until(BODY_VALUE_DELIM,
std::bind(&Request::handle_response_body, this, std::placeholders::_1, std::placeholders::_2)); 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) else if (connection_type_ == restinio::http_connection_header_t::close)
{ {
terminate(asio::error::eof); terminate(asio::error::eof);
Expand Down

0 comments on commit d77c868

Please sign in to comment.