diff --git a/silkworm/rpc/http/connection.cpp b/silkworm/rpc/http/connection.cpp index 4dd68b4f22..8225e26251 100644 --- a/silkworm/rpc/http/connection.cpp +++ b/silkworm/rpc/http/connection.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -126,6 +127,7 @@ Task Connection::open_stream() { try { boost::beast::http::response rsp{boost::beast::http::status::ok, request_http_version_}; rsp.set(boost::beast::http::field::content_type, "application/json"); + rsp.set(boost::beast::http::field::date, get_date_time()); rsp.chunked(true); set_cors(rsp); @@ -165,6 +167,8 @@ Task Connection::do_write(const std::string& content, boost::beast::http:: SILK_TRACE << "Connection::do_write response: " << content; boost::beast::http::response res{http_status, request_http_version_}; res.set(boost::beast::http::field::content_type, "application/json"); + res.set(boost::beast::http::field::date, get_date_time()); + res.erase(boost::beast::http::field::host); res.keep_alive(request_keep_alive_); res.content_length(content.size()); res.body() = content; @@ -241,4 +245,13 @@ void Connection::set_cors(boost::beast::http::response& res) { res.set("Access-Control-Max-Age", "600"); } +std::string Connection::get_date_time() { + static const absl::TimeZone tz{absl::LocalTimeZone()}; + const absl::Time now{absl::Now()}; + + std::stringstream ss; + ss << absl::FormatTime("%a, %d %b %E4Y %H:%M:%S ", now, tz) << tz.name(); + return ss.str(); +} + } // namespace silkworm::rpc::http diff --git a/silkworm/rpc/http/connection.hpp b/silkworm/rpc/http/connection.hpp index 6261b6b9b6..8fb4cdad0d 100644 --- a/silkworm/rpc/http/connection.hpp +++ b/silkworm/rpc/http/connection.hpp @@ -79,6 +79,8 @@ class Connection : public Channel { //! Perform an asynchronous write operation. Task do_write(const std::string& content, boost::beast::http::status http_status = boost::beast::http::status::ok); + static std::string get_date_time(); + //! Socket for the connection. boost::asio::ip::tcp::socket socket_;