Merge pull request #79 from makaveli/39-settable-server-name

Settable server name feature
This commit is contained in:
Farook Al-Sammarraie 2020-12-03 04:27:18 +03:00 committed by GitHub
commit 0e7cee6ef1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -89,6 +89,7 @@ int main()
//crow::logger::setHandler(std::make_shared<ExampleLogHandler>()); //crow::logger::setHandler(std::make_shared<ExampleLogHandler>());
app.port(18080) app.port(18080)
.server_name("CrowCpp")
.multithreaded() .multithreaded()
.run(); .run();
} }

View File

@ -96,6 +96,13 @@ namespace crow
return *this; 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) ///The IP address that Crow will handle requests on (default is 0.0.0.0)
self_t& bindaddr(std::string bindaddr) self_t& bindaddr(std::string bindaddr)
{ {
@ -174,7 +181,7 @@ namespace crow
#ifdef CROW_ENABLE_SSL #ifdef CROW_ENABLE_SSL
if (use_ssl_) if (use_ssl_)
{ {
ssl_server_ = std::move(std::unique_ptr<ssl_server_t>(new ssl_server_t(this, bindaddr_, port_, &middlewares_, concurrency_, &ssl_context_))); ssl_server_ = std::move(std::unique_ptr<ssl_server_t>(new ssl_server_t(this, bindaddr_, port_, server_name_, &middlewares_, concurrency_, &ssl_context_)));
ssl_server_->set_tick_function(tick_interval_, tick_function_); ssl_server_->set_tick_function(tick_interval_, tick_function_);
notify_server_start(); notify_server_start();
ssl_server_->run(); ssl_server_->run();
@ -182,7 +189,7 @@ namespace crow
else else
#endif #endif
{ {
server_ = std::move(std::unique_ptr<server_t>(new server_t(this, bindaddr_, port_, &middlewares_, concurrency_, nullptr))); server_ = std::move(std::unique_ptr<server_t>(new server_t(this, bindaddr_, port_, server_name_, &middlewares_, concurrency_, nullptr)));
server_->set_tick_function(tick_interval_, tick_function_); server_->set_tick_function(tick_interval_, tick_function_);
notify_server_start(); notify_server_start();
server_->run(); server_->run();
@ -311,6 +318,7 @@ namespace crow
private: private:
uint16_t port_ = 80; uint16_t port_ = 80;
uint16_t concurrency_ = 1; uint16_t concurrency_ = 1;
std::string server_name_ = "Crow/0.2";
std::string bindaddr_ = "0.0.0.0"; std::string bindaddr_ = "0.0.0.0";
Router router_; Router router_;

View File

@ -26,12 +26,13 @@ namespace crow
class Server class Server
{ {
public: public:
Server(Handler* handler, std::string bindaddr, uint16_t port, std::tuple<Middlewares...>* 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...>* 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)), : acceptor_(io_service_, tcp::endpoint(boost::asio::ip::address::from_string(bindaddr), port)),
signals_(io_service_, SIGINT, SIGTERM), signals_(io_service_, SIGINT, SIGTERM),
tick_timer_(io_service_), tick_timer_(io_service_),
handler_(handler), handler_(handler),
concurrency_(concurrency == 0 ? 1 : concurrency), concurrency_(concurrency == 0 ? 1 : concurrency),
server_name_(server_name),
port_(port), port_(port),
bindaddr_(bindaddr), bindaddr_(bindaddr),
middlewares_(middlewares), middlewares_(middlewares),
@ -218,7 +219,7 @@ namespace crow
Handler* handler_; Handler* handler_;
uint16_t concurrency_{1}; uint16_t concurrency_{1};
std::string server_name_ = "Crow/0.2"; std::string server_name_;
uint16_t port_; uint16_t port_;
std::string bindaddr_; std::string bindaddr_;
unsigned int roundrobin_index_{}; unsigned int roundrobin_index_{};