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

The main server application. More...

#include <app.h>

Public Types

using self_t = Crow
 This crow application.
 
using server_t = Server< Crow, SocketAdaptor, Middlewares... >
 The HTTP server.
 
using ssl_server_t = Server< Crow, SSLAdaptor, Middlewares... >
 An HTTP server that runs on SSL with an SSLAdaptor.
 
using context_t = detail::context< Middlewares... >
 
using mw_container_t = std::tuple< Middlewares... >
 

Public Member Functions

template<typename... Ts>
 Crow (Ts &&... ts)
 Construct Crow with a subset of middleware.
 
template<typename Adaptor >
void handle_upgrade (const request &req, response &res, Adaptor &&adaptor)
 Process an Upgrade request. More...
 
std::unique_ptr< routing_handle_resulthandle_initial (request &req, response &res)
 Process only the method and URL of a request and provide a route (or an error response)
 
void handle (request &req, response &res, std::unique_ptr< routing_handle_result > &found)
 Process the fully parsed request and generate a response for it.
 
void handle_full (request &req, response &res)
 Process a fully parsed request from start to finish (primarily used for debugging)
 
DynamicRuleroute_dynamic (const std::string &rule)
 Create a dynamic route using a rule (Use CROW_ROUTE instead)
 
template<uint64_t Tag>
auto route (const std::string &rule) -> typename std::result_of< decltype(&Router::new_rule_tagged< Tag >)(Router, const std::string &)>::type
 Create a route using a rule (Use CROW_ROUTE instead)
 
CatchallRulecatchall_route ()
 Create a route for any requests without a proper route (Use CROW_CATCHALL_ROUTE instead)
 
self_twebsocket_max_payload (uint64_t max_payload)
 Set the default max payload size for websockets.
 
uint64_t websocket_max_payload ()
 Get the default max payload size for websockets.
 
self_tsignal_clear ()
 
self_tsignal_add (int signal_number)
 
std::vector< int > signals ()
 
self_tport (std::uint16_t port)
 Set the port that Crow will handle requests on.
 
std::uint16_t port ()
 Get the port that Crow will handle requests on.
 
self_ttimeout (std::uint8_t timeout)
 Set the connection timeout in seconds (default is 5)
 
self_tserver_name (std::string server_name)
 Set the server name.
 
self_tbindaddr (std::string bindaddr)
 The IP address that Crow will handle requests on (default is 0.0.0.0)
 
std::string bindaddr ()
 Get the address that Crow will handle requests on.
 
self_tmultithreaded ()
 Run the server on multiple threads using all available threads.
 
self_tconcurrency (std::uint16_t concurrency)
 Run the server on multiple threads using a specific number.
 
std::uint16_t concurrency ()
 Get the number of threads that server is using.
 
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.
 
self_tregister_blueprint (Blueprint &blueprint)
 
template<typename Func >
self_texception_handler (Func &&f)
 Set the function to call to handle uncaught exceptions generated in routes (Default generates error 500). More...
 
std::function< void(crow::response &)> & exception_handler ()
 
template<typename Duration , typename Func >
self_ttick (Duration d, Func f)
 Set a custom duration and function to run on every tick.
 
self_tuse_compression (compression::algorithm algorithm)
 
compression::algorithm compression_algorithm ()
 
bool compression_used () const
 
void add_blueprint ()
 Apply blueprints.
 
void add_static_dir ()
 Go through the rules, upgrade them if possible, and add them to the list of rules.
 
void validate ()
 A wrapper for validate() in the router.
 
void run ()
 Run the server.
 
std::future< void > run_async ()
 
void stop ()
 Stop the server.
 
void add_websocket (crow::websocket::connection *conn)
 
void remove_websocket (crow::websocket::connection *conn)
 
void debug_print ()
 Print the routing paths defined for each HTTP method.
 
self_tssl_file (const std::string &crt_filename, const std::string &key_filename)
 Use certificate and key files for SSL.
 
self_tssl_file (const std::string &pem_filename)
 Use .pem file for SSL.
 
self_tssl_chainfile (const std::string &crt_filename, const std::string &key_filename)
 Use certificate chain and key files for SSL.
 
self_tssl (asio::ssl::context &&ctx)
 
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.
 

Detailed Description

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

The main server application.

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

Member Function Documentation

◆ exception_handler()

template<typename... Middlewares>
template<typename Func >
self_t& crow::Crow< Middlewares >::exception_handler ( Func &&  f)
inline

Set the function to call to handle uncaught exceptions generated in routes (Default generates error 500).

The function must have the following signature: void(crow::response&). It must set the response passed in argument to the function, which will be sent back to the client. See Router::default_exception_handler() for the default implementation.

◆ 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 upgrade an HTTP connection to a WebSocket connection

◆ 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)

◆ run_async()

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

Non-blocking version of run()

The output from this method needs to be saved into a variable! Otherwise the call will be made on the same thread.

◆ stream_threshold()

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.


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