maph 1.0.0 High-Performance Memory-Mapped Key-Value Database with O(1) Lookups

Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
httplib::Server Class Reference

`#include <httplib.h>`

Collaboration diagram for httplib::Server:

## Public Types
enum class | HandlerResponse { Handled , Unhandled }
using | Handler = std::function< void(const Request &, Response &)>
using | ExceptionHandler = std::function< void(const Request &, Response &, std::exception_ptr ep)>
using | HandlerWithResponse = std::function< HandlerResponse(const Request &, Response &)>
using | HandlerWithContentReader = std::function< void(const Request &, Response &, const ContentReader &content_reader)>
using | Expect100ContinueHandler = std::function< int(const Request &, Response &)>

## Public Member Functions
| Server ()
virtual | ~Server ()
virtual bool | is_valid () const
Server & | Get (const std::string &pattern, Handler handler)
Server & | Post (const std::string &pattern, Handler handler)
Server & | Post (const std::string &pattern, HandlerWithContentReader handler)
Server & | Put (const std::string &pattern, Handler handler)
Server & | Put (const std::string &pattern, HandlerWithContentReader handler)
Server & | Patch (const std::string &pattern, Handler handler)
Server & | Patch (const std::string &pattern, HandlerWithContentReader handler)
Server & | Delete (const std::string &pattern, Handler handler)
Server & | Delete (const std::string &pattern, HandlerWithContentReader handler)
Server & | Options (const std::string &pattern, Handler handler)
bool | set_base_dir (const std::string &dir, const std::string &mount_point=std::string())
bool | set_mount_point (const std::string &mount_point, const std::string &dir, Headers headers=Headers())
bool | remove_mount_point (const std::string &mount_point)
Server & | set_file_extension_and_mimetype_mapping (const std::string &ext, const std::string &mime)
Server & | set_default_file_mimetype (const std::string &mime)
Server & | set_file_request_handler (Handler handler)
template<class ErrorHandlerFunc >
Server & | set_error_handler (ErrorHandlerFunc &&handler)
Server & | set_exception_handler (ExceptionHandler handler)
Server & | set_pre_routing_handler (HandlerWithResponse handler)
Server & | set_post_routing_handler (Handler handler)
Server & | set_pre_request_handler (HandlerWithResponse handler)
Server & | set_expect_100_continue_handler (Expect100ContinueHandler handler)
Server & | set_logger (Logger logger)
Server & | set_pre_compression_logger (Logger logger)
Server & | set_error_logger (ErrorLogger error_logger)
Server & | set_address_family (int family)
Server & | set_tcp_nodelay (bool on)
Server & | set_ipv6_v6only (bool on)
Server & | set_socket_options (SocketOptions socket_options)
Server & | set_default_headers (Headers headers)
Server & | set_header_writer (std::function< ssize_t(Stream &, Headers &)> const &writer)
Server & | set_keep_alive_max_count (size_t count)
Server & | set_keep_alive_timeout (time_t sec)
Server & | set_read_timeout (time_t sec, time_t usec=0)
template<class Rep , class Period >
Server & | set_read_timeout (const std::chrono::duration< Rep, Period > &duration)
Server & | set_write_timeout (time_t sec, time_t usec=0)
template<class Rep , class Period >
Server & | set_write_timeout (const std::chrono::duration< Rep, Period > &duration)
Server & | set_idle_interval (time_t sec, time_t usec=0)
template<class Rep , class Period >
Server & | set_idle_interval (const std::chrono::duration< Rep, Period > &duration)
Server & | set_payload_max_length (size_t length)
bool | bind_to_port (const std::string &host, int port, int socket_flags=0)
int | bind_to_any_port (const std::string &host, int socket_flags=0)
bool | listen_after_bind ()
bool | listen (const std::string &host, int port, int socket_flags=0)
bool | is_running () const
void | wait_until_ready () const
void | stop ()
void | decommission ()

## Public Attributes
std::function< TaskQueue *(void)> | new_task_queue

## Protected Member Functions
bool | process_request (Stream &strm, const std::string &remote_addr, int remote_port, const std::string &local_addr, int local_port, bool close_connection, bool &connection_closed, const std::function< void(Request &)> &setup_request)

## Protected Attributes
std::atomic< socket_t > | svr_sock_ { (-1) }
size_t | keep_alive_max_count_ = 100
time_t | keep_alive_timeout_sec_ = 5
time_t | read_timeout_sec_ = 5
time_t | read_timeout_usec_ = 0
time_t | write_timeout_sec_ = 5
time_t | write_timeout_usec_ = 0
time_t | idle_interval_sec_ = 0
time_t | idle_interval_usec_ = 0
size_t | payload_max_length_ = ((std::numeric_limits<size_t>::max)())

## Detailed Description

Definition at line 1057 of file httplib.h.

## Member Typedef Documentation

## ◆ ExceptionHandler

using httplib::Server::ExceptionHandler = std::function<void(const Request &, Response &, std::exception_ptr ep)>

Definition at line 1061 of file httplib.h.

## ◆ Expect100ContinueHandler

using httplib::Server::Expect100ContinueHandler = std::function<int(const Request &, Response &)>

Definition at line 1074 of file httplib.h.

## ◆ Handler

using httplib::Server::Handler = std::function<void(const Request &, Response &)>

Definition at line 1059 of file httplib.h.

## ◆ HandlerWithContentReader

using httplib::Server::HandlerWithContentReader = std::function<void( const Request &, Response &, const ContentReader &content_reader)>

Definition at line 1071 of file httplib.h.

## ◆ HandlerWithResponse

using httplib::Server::HandlerWithResponse = std::function<HandlerResponse(const Request &, Response &)>

Definition at line 1068 of file httplib.h.

## Member Enumeration Documentation

## ◆ HandlerResponse

enum class httplib::Server::HandlerResponse
| strong

Enumerator
Handled |
Unhandled |

Definition at line 1064 of file httplib.h.

## Constructor & Destructor Documentation

## ◆ Server()

httplib::Server::Server | ( |  | ) |
| inline

Definition at line 7256 of file httplib.h.

References CPPHTTPLIB_THREAD_POOL_COUNT.

## ◆ ~Server()

httplib::Server::~Server | ( |  | ) |
| inline virtual default

## Member Function Documentation

## ◆ bind_to_any_port()

int httplib::Server::bind_to_any_port | ( | const std::string & | host,
|  | int | socket_flags = `0`
| ) |  |
| inline

Definition at line 7504 of file httplib.h.

## ◆ bind_to_port()

bool httplib::Server::bind_to_port | ( | const std::string & | host,
|  | int | port,
|  | int | socket_flags = `0`
| ) |  |
| inline

Definition at line 7498 of file httplib.h.

Referenced by listen().

Here is the caller graph for this function:

## ◆ decommission()

void httplib::Server::decommission | ( |  | ) |
| inline

Definition at line 7535 of file httplib.h.

## ◆ Delete() [1/2]

Server & httplib::Server::Delete | ( | const std::string & | pattern,
|  | Handler | handler
| ) |  |
| inline

Definition at line 7316 of file httplib.h.

Referenced by main().

Here is the caller graph for this function:

## ◆ Delete() [2/2]

Server & httplib::Server::Delete | ( | const std::string & | pattern,
|  | HandlerWithContentReader | handler
| ) |  |
| inline

Definition at line 7321 of file httplib.h.

## ◆ Get()

Server & httplib::Server::Get | ( | const std::string & | pattern,
|  | Handler | handler
| ) |  |
| inline

Definition at line 7275 of file httplib.h.

Referenced by main().

Here is the caller graph for this function:

## ◆ is_running()

bool httplib::Server::is_running | ( |  | ) | const
| inline

Definition at line 7517 of file httplib.h.

## ◆ is_valid()

bool httplib::Server::is_valid | ( |  | ) | const
| inline virtual

Definition at line 8454 of file httplib.h.

## ◆ listen()

bool httplib::Server::listen | ( | const std::string & | host,
|  | int | port,
|  | int | socket_flags = `0`
| ) |  |
| inline

Definition at line 7512 of file httplib.h.

References bind_to_port().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ listen_after_bind()

bool httplib::Server::listen_after_bind | ( |  | ) |
| inline

Definition at line 7510 of file httplib.h.

## ◆ Options()

Server & httplib::Server::Options | ( | const std::string & | pattern,
|  | Handler | handler
| ) |  |
| inline

Definition at line 7328 of file httplib.h.

Referenced by main().

Here is the caller graph for this function:

## ◆ Patch() [1/2]

Server & httplib::Server::Patch | ( | const std::string & | pattern,
|  | Handler | handler
| ) |  |
| inline

Definition at line 7304 of file httplib.h.

## ◆ Patch() [2/2]

Server & httplib::Server::Patch | ( | const std::string & | pattern,
|  | HandlerWithContentReader | handler
| ) |  |
| inline

Definition at line 7309 of file httplib.h.

## ◆ Post() [1/2]

Server & httplib::Server::Post | ( | const std::string & | pattern,
|  | Handler | handler
| ) |  |
| inline

Definition at line 7280 of file httplib.h.

Referenced by main().

Here is the caller graph for this function:

## ◆ Post() [2/2]

Server & httplib::Server::Post | ( | const std::string & | pattern,
|  | HandlerWithContentReader | handler
| ) |  |
| inline

Definition at line 7285 of file httplib.h.

## ◆ process_request()

bool httplib::Server::process_request | ( | Stream & | strm,
|  | const std::string & | remote_addr,
|  | int | remote_port,
|  | const std::string & | local_addr,
|  | int | local_port,
|  | bool | close_connection,
|  | bool & | connection_closed,
|  | const std::function< void(Request &)> & | setup_request
| ) |  |
| inline protected

Definition at line 8254 of file httplib.h.

References httplib::Request::accept_content_types, httplib::BadRequest_400, httplib::Response::body, httplib::Response::content_length_, httplib::Response::content_provider_, httplib::Continue_100, CPPHTTPLIB_REQUEST_URI_MAX_LENGTH, httplib::ExceedMaxSocketDescriptorCount, httplib::ExceedUriMaxLength, httplib::ExpectationFailed_417, httplib::Response::file_content_content_type_, httplib::Response::file_content_path_, httplib::Request::get_header_value(), httplib::Request::has_header(), httplib::Request::headers, httplib::Response::headers, httplib::HTTPParsing, httplib::InternalServerError_500, httplib::InvalidHeaders, httplib::InvalidRangeHeader, httplib::InvalidRequestLine, httplib::Request::is_connection_closed, httplib::Request::local_addr, httplib::Request::local_port, httplib::NotFound_404, httplib::OK_200, httplib::OpenFile, httplib::PartialContent_206, httplib::RangeNotSatisfiable_416, httplib::Request::ranges, httplib::Request::remote_addr, httplib::Request::remote_port, httplib::Response::set_content_provider(), httplib::Request::set_header(), httplib::Response::set_header(), httplib::Stream::socket(), httplib::Request::start_time_, httplib::Response::status, httplib::Request::target, httplib::UriTooLong_414, httplib::Request::version, httplib::Response::version, and httplib::Stream::write().

Here is the call graph for this function:

## ◆ Put() [1/2]

Server & httplib::Server::Put | ( | const std::string & | pattern,
|  | Handler | handler
| ) |  |
| inline

Definition at line 7292 of file httplib.h.

Referenced by main().

Here is the caller graph for this function:

## ◆ Put() [2/2]

Server & httplib::Server::Put | ( | const std::string & | pattern,
|  | HandlerWithContentReader | handler
| ) |  |
| inline

Definition at line 7297 of file httplib.h.

## ◆ remove_mount_point()

bool httplib::Server::remove_mount_point | ( | const std::string & | mount_point | ) |
| inline

Definition at line 7351 of file httplib.h.

## ◆ set_address_family()

Server & httplib::Server::set_address_family | ( | int | family | ) |
| inline

Definition at line 7434 of file httplib.h.

## ◆ set_base_dir()

bool httplib::Server::set_base_dir | ( | const std::string & | dir,
|  | const std::string & | mount_point = `std::string()`
| ) |  |
| inline

Definition at line 7333 of file httplib.h.

References set_mount_point().

Here is the call graph for this function:

## ◆ set_default_file_mimetype()

Server & httplib::Server::set_default_file_mimetype | ( | const std::string & | mime | ) |
| inline

Definition at line 7368 of file httplib.h.

## ◆ set_default_headers()

Server & httplib::Server::set_default_headers | ( | Headers | headers | ) |
| inline

Definition at line 7454 of file httplib.h.

## ◆ set_error_handler()

template<class ErrorHandlerFunc >

Server & httplib::Server::set_error_handler | ( | ErrorHandlerFunc && | handler | ) |
| inline

Definition at line 1105 of file httplib.h.

## ◆ set_error_logger()

Server & httplib::Server::set_error_logger | ( | ErrorLogger | error_logger | ) |
| inline

Definition at line 7418 of file httplib.h.

## ◆ set_exception_handler()

Server & httplib::Server::set_exception_handler | ( | ExceptionHandler | handler | ) |
| inline

Definition at line 7393 of file httplib.h.

## ◆ set_expect_100_continue_handler()

Server & httplib::Server::set_expect_100_continue_handler | ( | Expect100ContinueHandler | handler | ) |
| inline

Definition at line 7429 of file httplib.h.

## ◆ set_file_extension_and_mimetype_mapping()

Server & httplib::Server::set_file_extension_and_mimetype_mapping | ( | const std::string & | ext,
|  | const std::string & | mime
| ) |  |
| inline

Definition at line 7362 of file httplib.h.

## ◆ set_file_request_handler()

Server & httplib::Server::set_file_request_handler | ( | Handler | handler | ) |
| inline

Definition at line 7373 of file httplib.h.

## ◆ set_header_writer()

Server & httplib::Server::set_header_writer | ( | std::function< ssize_t(Stream &, Headers &)> const & | writer | ) |
| inline

Definition at line 7459 of file httplib.h.

## ◆ set_idle_interval() [1/2]

template<class Rep , class Period >

Server & httplib::Server::set_idle_interval | ( | const std::chrono::duration< Rep, Period > & | duration | ) |
| inline

Definition at line 2233 of file httplib.h.

References set_idle_interval().

Here is the call graph for this function:

## ◆ set_idle_interval() [2/2]

Server & httplib::Server::set_idle_interval | ( | time_t | sec,
|  | time_t | usec = `0`
| ) |  |
| inline

Definition at line 7487 of file httplib.h.

References idle_interval_sec_, and idle_interval_usec_.

Referenced by set_idle_interval().

Here is the caller graph for this function:

## ◆ set_ipv6_v6only()

Server & httplib::Server::set_ipv6_v6only | ( | bool | on | ) |
| inline

Definition at line 7444 of file httplib.h.

## ◆ set_keep_alive_max_count()

Server & httplib::Server::set_keep_alive_max_count | ( | size_t | count | ) |
| inline

Definition at line 7465 of file httplib.h.

References keep_alive_max_count_.

## ◆ set_keep_alive_timeout()

Server & httplib::Server::set_keep_alive_timeout | ( | time_t | sec | ) |
| inline

Definition at line 7470 of file httplib.h.

References keep_alive_timeout_sec_.

## ◆ set_logger()

Server & httplib::Server::set_logger | ( | Logger | logger | ) |
| inline

Definition at line 7413 of file httplib.h.

## ◆ set_mount_point()

bool httplib::Server::set_mount_point | ( | const std::string & | mount_point,
|  | const std::string & | dir,
|  | Headers | headers = `Headers()`
| ) |  |
| inline

Definition at line 7338 of file httplib.h.

Referenced by set_base_dir().

Here is the caller graph for this function:

## ◆ set_payload_max_length()

Server & httplib::Server::set_payload_max_length | ( | size_t | length | ) |
| inline

Definition at line 7493 of file httplib.h.

References payload_max_length_.

## ◆ set_post_routing_handler()

Server & httplib::Server::set_post_routing_handler | ( | Handler | handler | ) |
| inline

Definition at line 7403 of file httplib.h.

Referenced by main().

Here is the caller graph for this function:

## ◆ set_pre_compression_logger()

Server & httplib::Server::set_pre_compression_logger | ( | Logger | logger | ) |
| inline

Definition at line 7423 of file httplib.h.

## ◆ set_pre_request_handler()

Server & httplib::Server::set_pre_request_handler | ( | HandlerWithResponse | handler | ) |
| inline

Definition at line 7408 of file httplib.h.

## ◆ set_pre_routing_handler()

Server & httplib::Server::set_pre_routing_handler | ( | HandlerWithResponse | handler | ) |
| inline

Definition at line 7398 of file httplib.h.

## ◆ set_read_timeout() [1/2]

template<class Rep , class Period >

Server & httplib::Server::set_read_timeout | ( | const std::chrono::duration< Rep, Period > & | duration | ) |
| inline

Definition at line 2217 of file httplib.h.

References set_read_timeout().

Here is the call graph for this function:

## ◆ set_read_timeout() [2/2]

Server & httplib::Server::set_read_timeout | ( | time_t | sec,
|  | time_t | usec = `0`
| ) |  |
| inline

Definition at line 7475 of file httplib.h.

References read_timeout_sec_, and read_timeout_usec_.

Referenced by set_read_timeout().

Here is the caller graph for this function:

## ◆ set_socket_options()

Server & httplib::Server::set_socket_options | ( | SocketOptions | socket_options | ) |
| inline

Definition at line 7449 of file httplib.h.

## ◆ set_tcp_nodelay()

Server & httplib::Server::set_tcp_nodelay | ( | bool | on | ) |
| inline

Definition at line 7439 of file httplib.h.

## ◆ set_write_timeout() [1/2]

template<class Rep , class Period >

Server & httplib::Server::set_write_timeout | ( | const std::chrono::duration< Rep, Period > & | duration | ) |
| inline

Definition at line 2225 of file httplib.h.

References set_write_timeout().

Here is the call graph for this function:

## ◆ set_write_timeout() [2/2]

Server & httplib::Server::set_write_timeout | ( | time_t | sec,
|  | time_t | usec = `0`
| ) |  |
| inline

Definition at line 7481 of file httplib.h.

References write_timeout_sec_, and write_timeout_usec_.

Referenced by set_write_timeout().

Here is the caller graph for this function:

## ◆ stop()

void httplib::Server::stop | ( |  | ) |
| inline

Definition at line 7525 of file httplib.h.

References INVALID_SOCKET, and svr_sock_.

## ◆ wait_until_ready()

void httplib::Server::wait_until_ready | ( |  | ) | const
| inline

Definition at line 7519 of file httplib.h.

## Member Data Documentation

## ◆ idle_interval_sec_

time_t httplib::Server::idle_interval_sec_ = 0
| protected

Definition at line 1176 of file httplib.h.

Referenced by set_idle_interval().

## ◆ idle_interval_usec_

time_t httplib::Server::idle_interval_usec_ = 0
| protected

Definition at line 1177 of file httplib.h.

Referenced by set_idle_interval().

## ◆ keep_alive_max_count_

size_t httplib::Server::keep_alive_max_count_ = 100
| protected

Definition at line 1170 of file httplib.h.

Referenced by set_keep_alive_max_count().

## ◆ keep_alive_timeout_sec_

time_t httplib::Server::keep_alive_timeout_sec_ = 5
| protected

Definition at line 1171 of file httplib.h.

Referenced by set_keep_alive_timeout().

## ◆ new_task_queue

std::function<TaskQueue *(void)> httplib::Server::new_task_queue

Definition at line 1160 of file httplib.h.

## ◆ payload_max_length_

size_t httplib::Server::payload_max_length_ = ((std::numeric_limits<size_t>::max)())
| protected

Definition at line 1178 of file httplib.h.

Referenced by set_payload_max_length().

## ◆ read_timeout_sec_

time_t httplib::Server::read_timeout_sec_ = 5
| protected

Definition at line 1172 of file httplib.h.

Referenced by set_read_timeout().

## ◆ read_timeout_usec_

time_t httplib::Server::read_timeout_usec_ = 0
| protected

Definition at line 1173 of file httplib.h.

Referenced by set_read_timeout().

## ◆ svr_sock_

std::atomic<socket_t> httplib::Server::svr_sock_ { (-1) }
| protected

Definition at line 1169 of file httplib.h.

Referenced by stop().

## ◆ write_timeout_sec_

time_t httplib::Server::write_timeout_sec_ = 5
| protected

Definition at line 1174 of file httplib.h.

Referenced by set_write_timeout().

## ◆ write_timeout_usec_

time_t httplib::Server::write_timeout_usec_ = 0
| protected

Definition at line 1175 of file httplib.h.

Referenced by set_write_timeout().

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

- integrations/rest_api/httplib.h