Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Public Types | Public Member Functions | List of all members
seastar::httpd::routes Class Reference

Detailed Description

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 ()
 
routesput (operation_type type, const sstring &url, handler_base *handler)
 
handler_basedrop (operation_type type, const sstring &url)
 
routesadd (match_rule *rule, operation_type type=GET)
 
routesadd (operation_type type, const url &url, handler_base *handler)
 
routesadd_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_baseget_exact_match (operation_type type, const sstring &url) const
 
handler_baseget_handler (operation_type type, const sstring &url, parameters &params)
 
exception_handler_id register_exeption_handler (exception_handler_fun fun)
 
void remove_exception_handler (exception_handler_id id)
 
std::unique_ptr< http::replyexception_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_ruledel_cookie (rule_cookie cookie, operation_type type)
 

Constructor & Destructor Documentation

◆ ~routes()

seastar::httpd::routes::~routes ( )

The destructor deletes the match rules and handlers

Member Function Documentation

◆ add() [1/2]

routes & seastar::httpd::routes::add ( match_rule rule,
operation_type  type = GET 
)
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

Parameters
rulea rule to add
typethe operation type
Returns
itself
Attention
This method takes ownership of the match_rule pointer. It will be automatically deleted when the routes instance is destroyed.

◆ add() [2/2]

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

Parameters
type
url
handler
Returns
Attention
This method takes ownership of the handler's pointer.It will be automatically deleted when the routes instance is destroyed.

◆ add_cookie()

rule_cookie seastar::httpd::routes::add_cookie ( match_rule rule,
operation_type  type 
)
inline

Add a rule to be used.

Parameters
rulea rule to add
typethe operation type
Returns
a cookie using which the rule can be removed
Attention
This method takes ownership of the match_rule pointer. It will be automatically deleted when the routes instance is destroyed.

◆ add_default_handler()

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

Parameters
handler
Returns
Attention
The caller must keep the handler active as long as the route instance is active.

◆ del_cookie()

match_rule * seastar::httpd::routes::del_cookie ( rule_cookie  cookie,
operation_type  type 
)

Del a rule by cookie

Parameters
cookiea cookie returned previously by add_cookie
typethe operation type
Returns
the pointer to the rule
Attention
Ownership of the pointer is returned to the caller.

◆ drop()

handler_base * seastar::httpd::routes::drop ( operation_type  type,
const sstring &  url 
)

removing a handler from exact match

Parameters
urlthe url to match (note that url should start with /)
Returns
the current handler (to be removed by caller)

◆ get_exact_match()

handler_base * seastar::httpd::routes::get_exact_match ( operation_type  type,
const sstring &  url 
) const
inline

Search and return an exact match

Parameters
urlthe request url
Returns
the handler if exists or nullptr if it does not

◆ get_handler()

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

Parameters
typethe http operation type
urlthe request url
paramsa parameter object that will be filled during the match
Returns
a handler based on the type/url match

◆ handle()

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

Parameters
paththe url path found
reqthe http request
repthe http reply

◆ put()

routes & seastar::httpd::routes::put ( operation_type  type,
const sstring &  url,
handler_base handler 
)

adding a handler as an exact match

Parameters
urlthe url to match (note that url should start with /)
handlerthe desire handler
Returns
itself
Attention
If successful, this method takes ownership of the handler pointer. It will be automatically deleted when the routes instance is destroyed. However, if the method throws, the caller is responsible for deleting the handler pointer.

◆ register_exeption_handler()

exception_handler_id seastar::httpd::routes::register_exeption_handler ( exception_handler_fun  fun)
inline

The exception_handler_fun expect to call std::rethrow_exception(eptr); and catch only the exception it handles


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