Crow  1.0
A C++ microframework for the web
crow::Crow< Middlewares > Class Template Reference

The main server application. More...

Collaboration diagram for crow::Crow< Middlewares >:

Public Types

using self_t = Crow
 This crow application. More...
 
using server_t = Server< Crow, SocketAdaptor, Middlewares... >
 The HTTP server. More...
 
using context_t = detail::context< Middlewares... >
 
using mw_container_t = std::tuple< Middlewares... >
 

Public Member Functions

 Crow ()
 
template<typename Adaptor >
void handle_upgrade (const request &req, response &res, Adaptor &&adaptor)
 Process an Upgrade request. More...
 
void handle (request &req, response &res)
 Process the request and generate a response for it. More...
 
DynamicRuleroute_dynamic (std::string &&rule)
 Create a dynamic route using a rule (Use CROW_ROUTE instead) More...
 
template<uint64_t Tag>
auto route (std::string &&rule) -> typename std::result_of< decltype(&Router::new_rule_tagged< Tag >)(Router, std::string &&)>::type
 Create a route using a rule (Use CROW_ROUTE instead) More...
 
CatchallRulecatchall_route ()
 Create a route for any requests without a proper route (Use CROW_CATCHALL_ROUTE instead) More...
 
self_tsignal_clear ()
 
self_tsignal_add (int signal_number)
 
self_tport (std::uint16_t port)
 Set the port that Crow will handle requests on. More...
 
std::uint16_t port ()
 Get the port that Crow will handle requests on. More...
 
self_ttimeout (std::uint8_t timeout)
 Set the connection timeout in seconds (default is 5) More...
 
self_tserver_name (std::string server_name)
 Set the server name. More...
 
self_tbindaddr (std::string bindaddr)
 The IP address that Crow will handle requests on (default is 0.0.0.0) More...
 
self_tmultithreaded ()
 Run the server on multiple threads using all available threads. More...
 
self_tconcurrency (std::uint16_t concurrency)
 Run the server on multiple threads using a specific number. More...
 
self_tloglevel (LogLevel level)
 Set the server's log level. More...
 
self_tstream_threshold (size_t threshold)
 Set the response body size (in bytes) beyond which Crow automatically streams responses (Default is 1MiB) More...
 
size_t & stream_threshold ()
 Get the response body size (in bytes) beyond which Crow automatically streams responses. More...
 
self_tregister_blueprint (Blueprint &blueprint)
 
template<typename Duration , typename Func >
self_ttick (Duration d, Func f)
 Set a custom duration and function to run on every tick. More...
 
void validate ()
 A wrapper for validate() in the router. More...
 
void notify_server_start ()
 Notify anything using wait_for_server_start() to proceed. More...
 
void run ()
 Run the server. More...
 
std::future< void > run_async ()
 Non-blocking version of run() More...
 
void stop ()
 Stop the server. More...
 
void debug_print ()
 Print the routing paths defined for each HTTP method. More...
 
template<typename T , typename... Remain>
self_tssl_file (T &&, Remain &&...)
 
template<typename T >
self_tssl (T &&)
 
bool ssl_used () const
 
template<typename T >
T::context & get_context (const request &req)
 
template<typename T >
T & get_middleware ()
 
void wait_for_server_start ()
 Wait until the server has properly started. More...
 

Private Attributes

std::uint8_t timeout_ {5}
 
uint16_t port_ = 80
 
uint16_t concurrency_ = 2
 
bool validated_ = false
 
std::string server_name_ = std::string("Crow/") + VERSION
 
std::string bindaddr_ = "0.0.0.0"
 
size_t res_stream_threshold_ = 1048576
 
Router router_
 
std::chrono::milliseconds tick_interval_
 
std::function< void()> tick_function_
 
std::tuple< Middlewares... > middlewares_
 
std::unique_ptr< server_tserver_
 
std::vector< int > signals_ {SIGINT, SIGTERM}
 
bool server_started_ {false}
 
std::condition_variable cv_started_
 
std::mutex start_mutex_
 

Detailed Description

template<typename... Middlewares>
class crow::Crow< Middlewares >

The main server application.

Use SimpleApp or App<Middleware1, Middleware2, etc...>

Member Typedef Documentation

◆ self_t

template<typename... Middlewares>
using crow::Crow< Middlewares >::self_t = Crow

This crow application.

◆ server_t

template<typename... Middlewares>
using crow::Crow< Middlewares >::server_t = Server<Crow, SocketAdaptor, Middlewares...>

The HTTP server.

◆ context_t

template<typename... Middlewares>
using crow::Crow< Middlewares >::context_t = detail::context<Middlewares...>

◆ mw_container_t

template<typename... Middlewares>
using crow::Crow< Middlewares >::mw_container_t = std::tuple<Middlewares...>

Constructor & Destructor Documentation

◆ Crow()

template<typename... Middlewares>
crow::Crow< Middlewares >::Crow ( )
inline

Member Function Documentation

◆ handle_upgrade()

template<typename... Middlewares>
template<typename Adaptor >
void crow::Crow< Middlewares >::handle_upgrade ( const request req,
response res,
Adaptor &&  adaptor 
)
inline

Process an Upgrade request.

Currently used to upgrrade an HTTP connection to a WebSocket connection

Here is the call graph for this function:

◆ handle()

template<typename... Middlewares>
void crow::Crow< Middlewares >::handle ( request req,
response res 
)
inline

Process the request and generate a response for it.

Here is the call graph for this function:

◆ route_dynamic()

template<typename... Middlewares>
DynamicRule& crow::Crow< Middlewares >::route_dynamic ( std::string &&  rule)
inline

Create a dynamic route using a rule (Use CROW_ROUTE instead)

Here is the call graph for this function:

◆ route()

template<typename... Middlewares>
template<uint64_t Tag>
auto crow::Crow< Middlewares >::route ( std::string &&  rule) -> typename std::result_of<decltype (&Router::new_rule_tagged<Tag>)(Router, std::string&&)>::type
inline

Create a route using a rule (Use CROW_ROUTE instead)

Here is the call graph for this function:

◆ catchall_route()

template<typename... Middlewares>
CatchallRule& crow::Crow< Middlewares >::catchall_route ( )
inline

Create a route for any requests without a proper route (Use CROW_CATCHALL_ROUTE instead)

Here is the call graph for this function:

◆ signal_clear()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::signal_clear ( )
inline

◆ signal_add()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::signal_add ( int  signal_number)
inline

◆ port() [1/2]

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::port ( std::uint16_t  port)
inline

Set the port that Crow will handle requests on.

Here is the call graph for this function:

◆ port() [2/2]

template<typename... Middlewares>
std::uint16_t crow::Crow< Middlewares >::port ( )
inline

Get the port that Crow will handle requests on.

Here is the caller graph for this function:

◆ timeout()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::timeout ( std::uint8_t  timeout)
inline

Set the connection timeout in seconds (default is 5)

◆ server_name()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::server_name ( std::string  server_name)
inline

Set the server name.

◆ bindaddr()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::bindaddr ( std::string  bindaddr)
inline

The IP address that Crow will handle requests on (default is 0.0.0.0)

◆ multithreaded()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::multithreaded ( )
inline

Run the server on multiple threads using all available threads.

Here is the call graph for this function:

◆ concurrency()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::concurrency ( std::uint16_t  concurrency)
inline

Run the server on multiple threads using a specific number.

Here is the caller graph for this function:

◆ loglevel()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::loglevel ( LogLevel  level)
inline

Set the server's log level.

Possible values are:
crow::LogLevel::Debug (0)
crow::LogLevel::Info (1)
crow::LogLevel::Warning (2)
crow::LogLevel::Error (3)
crow::LogLevel::Critical (4)

Here is the call graph for this function:

◆ stream_threshold() [1/2]

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::stream_threshold ( size_t  threshold)
inline

Set the response body size (in bytes) beyond which Crow automatically streams responses (Default is 1MiB)

Any streamed response is unaffected by Crow's timer, and therefore won't timeout before a response is fully sent.

◆ stream_threshold() [2/2]

template<typename... Middlewares>
size_t& crow::Crow< Middlewares >::stream_threshold ( )
inline

Get the response body size (in bytes) beyond which Crow automatically streams responses.

◆ register_blueprint()

template<typename... Middlewares>
self_t& crow::Crow< Middlewares >::register_blueprint ( Blueprint blueprint)
inline
Here is the call graph for this function:

◆ tick()

template<typename... Middlewares>
template<typename Duration , typename Func >
self_t& crow::Crow< Middlewares >::tick ( Duration  d,
Func  f 
)
inline

Set a custom duration and function to run on every tick.

◆ validate()

template<typename... Middlewares>
void crow::Crow< Middlewares >::validate ( )
inline

A wrapper for validate() in the router.

Go through the rules, upgrade them if possible, and add them to the list of rules

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_server_start()

template<typename... Middlewares>
void crow::Crow< Middlewares >::notify_server_start ( )
inline

Notify anything using wait_for_server_start() to proceed.

Here is the caller graph for this function:

◆ run()

template<typename... Middlewares>
void crow::Crow< Middlewares >::run ( )
inline

Run the server.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_async()

template<typename... Middlewares>
std::future<void> crow::Crow< Middlewares >::run_async ( )
inline

Non-blocking version of run()

Here is the call graph for this function:

◆ stop()

template<typename... Middlewares>
void crow::Crow< Middlewares >::stop ( )
inline

Stop the server.

◆ debug_print()

template<typename... Middlewares>
void crow::Crow< Middlewares >::debug_print ( )
inline

Print the routing paths defined for each HTTP method.

Here is the call graph for this function:

◆ ssl_file()

template<typename... Middlewares>
template<typename T , typename... Remain>
self_t& crow::Crow< Middlewares >::ssl_file ( T &&  ,
Remain &&  ... 
)
inline

◆ ssl()

template<typename... Middlewares>
template<typename T >
self_t& crow::Crow< Middlewares >::ssl ( T &&  )
inline

◆ ssl_used()

template<typename... Middlewares>
bool crow::Crow< Middlewares >::ssl_used ( ) const
inline

◆ get_context()

template<typename... Middlewares>
template<typename T >
T::context& crow::Crow< Middlewares >::get_context ( const request req)
inline

◆ get_middleware()

template<typename... Middlewares>
template<typename T >
T& crow::Crow< Middlewares >::get_middleware ( )
inline

◆ wait_for_server_start()

template<typename... Middlewares>
void crow::Crow< Middlewares >::wait_for_server_start ( )
inline

Wait until the server has properly started.

Member Data Documentation

◆ timeout_

template<typename... Middlewares>
std::uint8_t crow::Crow< Middlewares >::timeout_ {5}
private

◆ port_

template<typename... Middlewares>
uint16_t crow::Crow< Middlewares >::port_ = 80
private

◆ concurrency_

template<typename... Middlewares>
uint16_t crow::Crow< Middlewares >::concurrency_ = 2
private

◆ validated_

template<typename... Middlewares>
bool crow::Crow< Middlewares >::validated_ = false
private

◆ server_name_

template<typename... Middlewares>
std::string crow::Crow< Middlewares >::server_name_ = std::string("Crow/") + VERSION
private

◆ bindaddr_

template<typename... Middlewares>
std::string crow::Crow< Middlewares >::bindaddr_ = "0.0.0.0"
private

◆ res_stream_threshold_

template<typename... Middlewares>
size_t crow::Crow< Middlewares >::res_stream_threshold_ = 1048576
private

◆ router_

template<typename... Middlewares>
Router crow::Crow< Middlewares >::router_
private

◆ tick_interval_

template<typename... Middlewares>
std::chrono::milliseconds crow::Crow< Middlewares >::tick_interval_
private

◆ tick_function_

template<typename... Middlewares>
std::function<void()> crow::Crow< Middlewares >::tick_function_
private

◆ middlewares_

template<typename... Middlewares>
std::tuple<Middlewares...> crow::Crow< Middlewares >::middlewares_
private

◆ server_

template<typename... Middlewares>
std::unique_ptr<server_t> crow::Crow< Middlewares >::server_
private

◆ signals_

template<typename... Middlewares>
std::vector<int> crow::Crow< Middlewares >::signals_ {SIGINT, SIGTERM}
private

◆ server_started_

template<typename... Middlewares>
bool crow::Crow< Middlewares >::server_started_ {false}
private

◆ cv_started_

template<typename... Middlewares>
std::condition_variable crow::Crow< Middlewares >::cv_started_
private

◆ start_mutex_

template<typename... Middlewares>
std::mutex crow::Crow< Middlewares >::start_mutex_
private

The documentation for this class was generated from the following file: