Add expires_after in onRead()

This commit is contained in:
Andrey Kutin 2026-08-06 09:15:29 +03:00
parent cfcc33a43f
commit 7387cc4611
1 changed files with 5 additions and 3 deletions

View File

@ -1,4 +1,5 @@
#include "server.hpp"
#include <boost/asio/detail/chrono.hpp>
#include <iostream>
#include <chrono>
@ -12,6 +13,7 @@ void HttpSession::run() {
void HttpSession::readRequest() {
req = {};
stream.expires_after(net::chrono::seconds(15));
http::async_read(
stream,
buffer,
@ -33,7 +35,7 @@ void HttpSession::onRead(beast::error_code ec, std::size_t) {
void HttpSession::processRequest(http::request<http::string_body>&& request) {
http::response<http::string_body> res{http::status::ok, request.version()};
res.set(http::field::server, "Boost.Beast Server");
res.set(http::field::server, "Cards Server");
res.set(http::field::content_type, "application/json");
try {
@ -62,7 +64,7 @@ void HttpSession::processRequest(http::request<http::string_body>&& request) {
res.result(http::status::not_found);
json error = {
{"error", "Not Found"},
{"path", request.target()}
//{"path", request.target()}
};
res.body() = error.dump(4);
}
@ -70,7 +72,7 @@ void HttpSession::processRequest(http::request<http::string_body>&& request) {
res.result(http::status::internal_server_error);
json error = {
{"error", "Internal Server Error"},
{"message", e.what()}
//{"message", e.what()}
};
res.body() = error.dump(4);
}