diff --git a/examples/example_with_all.cpp b/examples/example_with_all.cpp index 9661e7546..2b954cd67 100644 --- a/examples/example_with_all.cpp +++ b/examples/example_with_all.cpp @@ -89,6 +89,7 @@ int main() //crow::logger::setHandler(std::make_shared()); app.port(18080) + .server_name("CrowCpp") .multithreaded() .run(); } diff --git a/include/crow/app.h b/include/crow/app.h index 718019179..8eb0de3e6 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -96,6 +96,13 @@ namespace crow return *this; } + ///Set the server name (default Crow/0.2) + self_t& server_name(std::string server_name) + { + server_name_ = server_name; + return *this; + } + ///The IP address that Crow will handle requests on (default is 0.0.0.0) self_t& bindaddr(std::string bindaddr) { @@ -174,7 +181,7 @@ namespace crow #ifdef CROW_ENABLE_SSL if (use_ssl_) { - ssl_server_ = std::move(std::unique_ptr(new ssl_server_t(this, bindaddr_, port_, &middlewares_, concurrency_, &ssl_context_))); + ssl_server_ = std::move(std::unique_ptr(new ssl_server_t(this, bindaddr_, port_, server_name_, &middlewares_, concurrency_, &ssl_context_))); ssl_server_->set_tick_function(tick_interval_, tick_function_); notify_server_start(); ssl_server_->run(); @@ -182,7 +189,7 @@ namespace crow else #endif { - server_ = std::move(std::unique_ptr(new server_t(this, bindaddr_, port_, &middlewares_, concurrency_, nullptr))); + server_ = std::move(std::unique_ptr(new server_t(this, bindaddr_, port_, server_name_, &middlewares_, concurrency_, nullptr))); server_->set_tick_function(tick_interval_, tick_function_); notify_server_start(); server_->run(); @@ -311,6 +318,7 @@ namespace crow private: uint16_t port_ = 80; uint16_t concurrency_ = 1; + std::string server_name_ = "Crow/0.2"; std::string bindaddr_ = "0.0.0.0"; Router router_; diff --git a/include/crow/http_server.h b/include/crow/http_server.h index a7039d639..936e903fe 100644 --- a/include/crow/http_server.h +++ b/include/crow/http_server.h @@ -26,12 +26,13 @@ namespace crow class Server { public: - Server(Handler* handler, std::string bindaddr, uint16_t port, std::tuple* middlewares = nullptr, uint16_t concurrency = 1, typename Adaptor::context* adaptor_ctx = nullptr) + Server(Handler* handler, std::string bindaddr, uint16_t port, std::string server_name = "Crow/0.2", std::tuple* middlewares = nullptr, uint16_t concurrency = 1, typename Adaptor::context* adaptor_ctx = nullptr) : acceptor_(io_service_, tcp::endpoint(boost::asio::ip::address::from_string(bindaddr), port)), signals_(io_service_, SIGINT, SIGTERM), tick_timer_(io_service_), handler_(handler), concurrency_(concurrency == 0 ? 1 : concurrency), + server_name_(server_name), port_(port), bindaddr_(bindaddr), middlewares_(middlewares), @@ -218,7 +219,7 @@ namespace crow Handler* handler_; uint16_t concurrency_{1}; - std::string server_name_ = "Crow/0.2"; + std::string server_name_; uint16_t port_; std::string bindaddr_; unsigned int roundrobin_index_{};