1 #ifndef jb_ehs_request_dispatcher_hpp 2 #define jb_ehs_request_dispatcher_hpp 23 std::function<void(request_type const&, response_type&)>;
204 std::pair<request_handler, bool>
find_handler(beast::string_view path)
const;
275 #endif // jb_ehs_request_dispatcher_hpp long get_open_connection() const
Returns the count of open connections.
std::atomic< long > close_connection_
response_type not_found(request_type const &request)
Create a 404 response.
std::map< std::string, request_handler > handlers_
The collection of handlers.
std::atomic< long > write_100_
beast::http::request< beast::http::string_body > request_type
The request type used for JayBeams Embedded HTTP Servers.
std::atomic< long > open_connection_
Multiple counters.
void count_write_error()
Count a write errors.
void count_accept_ok()
Count accept successes.
long get_accept_error() const
void count_open_connection()
Event counters.
long get_read_ok() const
Get the count of successful reads.
void count_write_100()
Count a write in the 100 range.
long get_accept_closed() const
long get_close_connection() const
Get the count of close connections.
std::atomic< long > write_ok_
std::atomic< long > read_error_
void append_metrics(response_type &res) const
Append the internal metrics to the body of res.
void count_write_invalid()
Internally updated event counters.
std::atomic< long > write_error_
void count_write_ok()
Count a write successes.
void count_accept_closed()
Count accept requests on closed acceptors (rare)
Holds a collection of HTTP request handlers and forwards requests.
std::atomic< long > write_invalid_
long get_write_400() const
Get the count write in the 400 range.
beast::http::response< beast::http::string_body > response_type
The response type used for JayBeams Embedded HTTP Servers.
request_dispatcher(std::string const &server_name)
Create a new empty dispatcher.
std::atomic< long > write_500_
void count_write_500()
Count a write in the 500 range.
response_type internal_error(request_type const &request)
Create a 500 response.
void count_close_connection()
Count a new connection closed.
std::atomic< long > accept_error_
std::mutex mu_
Protect the critical sections.
std::atomic< long > write_300_
void count_read_error()
Count a write errors.
long get_write_invalid() const
Get count of responses with invalid codes (outside the [100,600) range).
std::function< void(request_type const &, response_type &)> request_handler
Define the interface for request handlers.
void count_read_ok()
Count a successful read.
std::atomic< long > write_200_
long get_write_100() const
Get the count write in the 100 range.
std::string server_name_
The name of the server returned in all HTTP responses.
std::atomic< long > accept_ok_
void count_write_200()
Count a write in the 200 range.
long get_write_300() const
Get the count write in the 300 range.
long get_accept_ok() const
long get_write_500() const
Get the count write in the 500 range.
std::atomic< long > accept_closed_
long get_read_error() const
Get the count write errors.
void count_write_400()
Count a write in the 400 range.
std::atomic< long > read_ok_
long get_write_200() const
Get the count write in the 200 range.
void update_response_counter(response_type const &res)
Update the response code counters based on res.
long get_write_error() const
Get the count write errors.
void count_accept_error()
Count accept errors.
std::atomic< long > write_400_
response_type process(request_type const &request)
Process a new request using the right handler.
std::pair< request_handler, bool > find_handler(beast::string_view path) const
Find the request handler for the given path.
long get_write_ok() const
Get the count write successes.
void count_write_300()
Count a write in the 300 range.
The top-level namespace for the JayBeams library.
void add_handler(std::string const &path, request_handler &&handler)
Add a new handler.