From 8d2637e6a5f71bf0d0a7d930fdfb29d9f289e256 Mon Sep 17 00:00:00 2001 From: Matt Witherspoon <32485495+spoonincode@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:53:57 -0400 Subject: [PATCH] change the HTTP Server header to be nodeos/keosd version --- plugins/http_plugin/http_plugin.cpp | 2 ++ .../include/eosio/http_plugin/beast_http_session.hpp | 3 ++- plugins/http_plugin/include/eosio/http_plugin/common.hpp | 2 ++ plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp | 2 ++ programs/keosd/main.cpp | 3 ++- programs/nodeos/main.cpp | 3 ++- 6 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/http_plugin/http_plugin.cpp b/plugins/http_plugin/http_plugin.cpp index 597434c013..b445d4effa 100644 --- a/plugins/http_plugin/http_plugin.cpp +++ b/plugins/http_plugin/http_plugin.cpp @@ -359,6 +359,8 @@ class http_plugin_impl : public std::enable_shared_from_this { } } + my->plugin_state->server_header = current_http_plugin_defaults.server_header; + //watch out for the returns above when adding new code here } FC_LOG_AND_RETHROW() diff --git a/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp b/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp index d60fbb777c..d527feab37 100644 --- a/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp +++ b/plugins/http_plugin/include/eosio/http_plugin/beast_http_session.hpp @@ -106,7 +106,8 @@ class beast_http_session : public detail::abstract_conn { res_->version(req.version()); res_->set(http::field::content_type, "application/json"); res_->keep_alive(req.keep_alive()); - res_->set(http::field::server, BOOST_BEAST_VERSION_STRING); + if(plugin_state_->server_header.size()) + res_->set(http::field::server, plugin_state_->server_header); // Request path must be absolute and not contain "..". if(req.target().empty() || req.target()[0] != '/' || req.target().find("..") != beast::string_view::npos) { diff --git a/plugins/http_plugin/include/eosio/http_plugin/common.hpp b/plugins/http_plugin/include/eosio/http_plugin/common.hpp index ecd3bbb676..cf97777b9c 100644 --- a/plugins/http_plugin/include/eosio/http_plugin/common.hpp +++ b/plugins/http_plugin/include/eosio/http_plugin/common.hpp @@ -130,6 +130,8 @@ struct http_plugin_state { bool validate_host = true; set valid_hosts; + string server_header; + url_handlers_type url_handlers; bool keep_alive = false; diff --git a/plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp b/plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp index c0ad27ddd3..58323adb04 100644 --- a/plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp +++ b/plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp @@ -45,6 +45,8 @@ namespace eosio { //If non 0, HTTP will be enabled by default on the given port number. If // 0, HTTP will not be enabled by default uint16_t default_http_port{0}; + //If set, a Server header will be added to the HTTP reply with this value + string server_header; }; /** diff --git a/programs/keosd/main.cpp b/programs/keosd/main.cpp index e3391fe951..caaeb4587d 100644 --- a/programs/keosd/main.cpp +++ b/programs/keosd/main.cpp @@ -81,7 +81,8 @@ int main(int argc, char** argv) app().set_default_config_dir(home / "eosio-wallet"); http_plugin::set_defaults({ .default_unix_socket_path = keosd::config::key_store_executable_name + ".sock", - .default_http_port = 0 + .default_http_port = 0, + .server_header = keosd::config::key_store_executable_name + "/" + app().version_string() }); app().register_plugin(); if(!app().initialize(argc, argv)) { diff --git a/programs/nodeos/main.cpp b/programs/nodeos/main.cpp index 6576235c7d..b9cebe310a 100644 --- a/programs/nodeos/main.cpp +++ b/programs/nodeos/main.cpp @@ -120,7 +120,8 @@ int main(int argc, char** argv) app().set_default_config_dir(root / "eosio" / nodeos::config::node_executable_name / "config" ); http_plugin::set_defaults({ .default_unix_socket_path = "", - .default_http_port = 8888 + .default_http_port = 8888, + .server_header = nodeos::config::node_executable_name + "/" + app().version_string() }); if(!app().initialize(argc, argv)) { const auto& opts = app().get_options();