|
Malloy
|
#include <router.hpp>
Public Types | |
| template<typename Derived > | |
| using | req_generator = std::shared_ptr< typename http::connection< Derived >::request_generator > |
| using | request_header = boost::beast::http::request_header<> |
| using | method_type = malloy::http::method |
| using | request_type = malloy::http::request<> |
| using | response_type = malloy::http::response<> |
Public Member Functions | |
| router ()=default | |
| router (std::shared_ptr< spdlog::logger > logger) | |
| router (const router &other)=delete | |
| router (router &&other) noexcept=default | |
| ~router ()=default | |
| router & | operator= (const router &rhs)=delete |
| router & | operator= (router &&rhs) noexcept=default |
| void | set_logger (std::shared_ptr< spdlog::logger > logger) |
| bool | add_subrouter (std::string resource, std::unique_ptr< router > sub_router) |
| bool | add_subrouter (std::string resource, router &&sub_router) |
| template<concepts::request_filter ExtraInfo, concepts::route_handler< typename ExtraInfo::request_type > Func> | |
| bool | add (const method_type method, const std::string_view target, Func &&handler, ExtraInfo &&extra) |
| template<concepts::route_handler< typename detail::default_route_filter::request_type > Func> | |
| auto | add (const method_type method, const std::string_view target, Func &&handler) |
| bool | add_preflight (std::string_view target, http::preflight_config cfg) |
| template<malloy::concepts::callable_string CacheControl> | |
| bool | add_file_serving (std::string resource, std::filesystem::path storage_base_path, const CacheControl &cc) |
| bool | add_file_serving (std::string resource, std::filesystem::path storage_base_path) |
| bool | add_redirect (malloy::http::status status, std::string &&resource_old, std::string &&resource_new) |
| bool | add_websocket (std::string &&resource, typename websocket::connection::handler_t &&handler) |
| template<concepts::request_validator Policy> | |
| void | add_policy (const std::string &resource, Policy &&policy) |
| template<bool isWebsocket = false, typename Derived , typename Connection > | |
| void | handle_request (const std::filesystem::path &doc_root, const req_generator< Derived > &req, Connection &&connection) |
| constexpr std::string_view | server_string () const |
Friends | |
| class | routing_context |
An HTTP request router.
This class implements a basic router for HTTP requests.
The method type to use.
The request type to use.
The response type to use.
|
default |
Default constructor.
|
explicit |
Constructor.
| logger | The logger instance to use. |
|
delete |
Copy constructor.
|
defaultnoexcept |
Move constructor.
|
default |
Destructor.
|
inline |
Add an HTTP regex endpoint.
| ExtraInfo | a type that satisfies request_filter. Used to provide additional customisation of request handling. Must satisfy request_filter Route concepts |
| Func | invoked on a request to the specified target with the specified method. Must satisfy route_handler Route concepts |
| method | The HTTP method. |
| target | The resource path (regex). |
| handler | The handler to generate the response. |
|
inline |
Add an HTTP file-serving location.
| resource | |
| storage_base_path |

|
inline |
Add an HTTP file-servinc location.
| CacheControl |
| resource | |
| storage_base_path | |
| cc |
|
inline |
Add an access policy for a specific resource.
A policy allow restricting access to any resource registered on this router.
| resource | The resource path. |
| policy | The policy. |
| bool router::add_redirect | ( | malloy::http::status | status, |
| std::string && | resource_old, | ||
| std::string && | resource_new | ||
| ) |
Adds an HTTP redirection rule.
| resource_old | |
| resource_new | |
| status | The HTTP status code to use. This must be a 3xx status code. |
| bool router::add_subrouter | ( | std::string | resource, |
| router && | sub_router | ||
| ) |
Add a sub-router for a specific resource.
| resource | The resource base path for the sub-router. |
| sub_router | The sub-router. |

| bool router::add_subrouter | ( | std::string | resource, |
| std::unique_ptr< router > | sub_router | ||
| ) |
Add a sub-router for a specific resource.
| resource | The resource base path for the sub-router. |
| sub_router | The sub-router. |
| bool router::add_websocket | ( | std::string && | resource, |
| typename websocket::connection::handler_t && | handler | ||
| ) |
Add a websocket endpoint.
| resource | The resource path. |
| handler | The handler for incoming websocket requests. |
|
inline |
Handle a request.
This function will either:
HTTP requests are first policy checked.
| isWebsocket | |
| Connection |
| doc_root | |
| req | The HTTP request to handle. |
| connection | The HTTP or WS connection. |
Copy assignment operator.
| rhs | The right-hand-side object to copy-assign from. |
Move assignment operator.
| rhs | The right-hand-side object to move-assign from. |
| void router::set_logger | ( | std::shared_ptr< spdlog::logger > | logger | ) |
Set the logger to use.
| logger | The logger to use. |