Seastar
High performance C++ framework for concurrent servers
|
routes object do the request dispatching according to the url. It uses two decision mechanism exact match, if a url matches exactly (an optional leading slash is permitted) it is chosen If not, the matching rules are used. matching rules are evaluated by their insertion order
#include <seastar/http/routes.hh>
Public Types | |
using | rule_cookie = uint64_t |
using | exception_handler_fun = std::function< std::unique_ptr< http::reply >(std::exception_ptr eptr)> |
using | exception_handler_id = size_t |
Public Member Functions | |
~routes () | |
routes & | put (operation_type type, const sstring &url, handler_base *handler) |
handler_base * | drop (operation_type type, const sstring &url) |
routes & | add (match_rule *rule, operation_type type=GET) |
routes & | add (operation_type type, const url &url, handler_base *handler) |
routes & | add_default_handler (handler_base *handler) |
future< std::unique_ptr< http::reply > > | handle (const sstring &path, std::unique_ptr< http::request > req, std::unique_ptr< http::reply > rep) |
handler_base * | get_exact_match (operation_type type, const sstring &url) const |
handler_base * | get_handler (operation_type type, const sstring &url, parameters ¶ms) |
exception_handler_id | register_exeption_handler (exception_handler_fun fun) |
void | remove_exception_handler (exception_handler_id id) |
std::unique_ptr< http::reply > | exception_reply (std::exception_ptr eptr) |
void | add_alias (const path_description &old_path, const path_description &new_path) |
add an alias to an already registered path. After registering a handler to a path, use this method to add an alias to that handler. | |
rule_cookie | add_cookie (match_rule *rule, operation_type type) |
match_rule * | del_cookie (rule_cookie cookie, operation_type type) |
seastar::httpd::routes::~routes | ( | ) |
The destructor deletes the match rules and handlers
|
inline |
add a rule to be used. rules are search only if an exact match was not found. rules are search by the order they were added. First in higher priority
rule | a rule to add |
type | the operation type |
routes & seastar::httpd::routes::add | ( | operation_type | type, |
const url & | url, | ||
handler_base * | handler | ||
) |
Add a url match to a handler: Example routes.add(GET, url("/api").remainder("path"), handler);
type | |
url | |
handler |
|
inline |
Add a rule to be used.
rule | a rule to add |
type | the operation type |
routes & seastar::httpd::routes::add_default_handler | ( | handler_base * | handler | ) |
Add a default handler - handles any HTTP Method and Path (/*) combination: Example routes.add_default_handler(handler);
handler |
handler
active as long as the route instance is active. match_rule * seastar::httpd::routes::del_cookie | ( | rule_cookie | cookie, |
operation_type | type | ||
) |
Del a rule by cookie
cookie | a cookie returned previously by add_cookie |
type | the operation type |
handler_base * seastar::httpd::routes::drop | ( | operation_type | type, |
const sstring & | url | ||
) |
removing a handler from exact match
url | the url to match (note that url should start with /) |
|
inline |
Search and return an exact match
url | the request url |
handler_base * seastar::httpd::routes::get_handler | ( | operation_type | type, |
const sstring & | url, | ||
parameters & | params | ||
) |
Search and return a handler by the operation type and url
type | the http operation type |
url | the request url |
params | a parameter object that will be filled during the match |
future< std::unique_ptr< http::reply > > seastar::httpd::routes::handle | ( | const sstring & | path, |
std::unique_ptr< http::request > | req, | ||
std::unique_ptr< http::reply > | rep | ||
) |
the main entry point. the general handler calls this method with the request the method takes the headers from the request and find the right handler. It then calls the handler with the parameters (if they exist) found in the url
path | the url path found |
req | the http request |
rep | the http reply |
routes & seastar::httpd::routes::put | ( | operation_type | type, |
const sstring & | url, | ||
handler_base * | handler | ||
) |
adding a handler as an exact match
url | the url to match (note that url should start with /) |
handler | the desire handler |
|
inline |
The exception_handler_fun expect to call std::rethrow_exception(eptr); and catch only the exception it handles