class http_server#
-
class http_server#
An HTTP Server for handling client requests.
Public Functions
-
inline auto max_listen_connections() const noexcept -> int#
Get the number of maximum concurrent connections.
-
inline auto tls_handshake_timeout() const noexcept -> optional<duration_type>#
Get the timeout for TLS handshake.
- DESCRIPTION
Get the timeout for TLS handshake. If no timeout is set,
nulloptis returned.
-
inline auto request_timeout() const noexcept -> optional<duration_type>#
Get the timeout for serving client request.
- DESCRIPTION
Get the timeout for serving client request. If no timeout is set,
nulloptis returned.
-
inline auto request_header_limit() const noexcept -> optional<std::uint32_t>#
Get the maximum size in bytes for reading client request headers.
- DESCRIPTION
Get the maximum size in bytes for reading client request headers.
nulloptindicates no size check will be performed.
-
inline auto request_body_limit() const noexcept -> optional<std::uint64_t>#
Get the maximum size in bytes for reading client request body.
- DESCRIPTION
Get the maximum size in bytes for reading client request body.
nulloptindicates no size check will be performed.
-
inline auto bind(std::string_view ip_addr, std::uint16_t port) const -> expected<const http_server&, std::error_code>#
Binds address and create an acceptor for TCP connections.
-
inline auto bind(std::string_view ip_addr, std::uint16_t port, net::ssl::context &ssl_ctx) const -> expected<const http_server&, std::error_code>#
Binds address and create an acceptor for TLS connections.
-
inline auto bind_local(std::string_view file_path) const -> expected<const http_server&, std::error_code>#
Binds address and create an acceptor for local (Unix domain socket) connections.
- DESCRIPTION
Binds address and create an acceptor for local (Unix domain socket) connections. Make sure that no file is at the
file_path, or system callbindmay return error.
-
inline auto bind_local(std::string_view file_path, net::ssl::context &ssl_ctx) const -> expected<const http_server&, std::error_code>#
Binds address and create an acceptor for local (Unix domain socket) TLS connections.
- DESCRIPTION
Binds address and create an acceptor for local (Unix domain socket) TLS connections. Make sure that no file is at the
file_path, or system callbindmay return error.
-
template<typename ResponseHandler>
inline void serve_request(std::string path, test_request req, ResponseHandler handler) const# Provides testing with a mock
test_requestagainst thehttp_serverusing fake connections.
-
class builder#
Public Functions
-
inline auto set_max_listen_connections(int num) & noexcept -> builder&#
Set the number of maximum concurrent connections.
-
inline auto set_tls_handshake_timeout(optional<duration_type> timeout) & noexcept -> builder&#
Set the timeout for TLS handshake.
- DESCRIPTION
Set the timeout for TLS handshake. Pass
nulloptto disable timeout.
-
inline auto set_request_timeout(optional<duration_type> timeout) & noexcept -> builder&#
Set the timeout for serving client request.
- DESCRIPTION
Set the timeout for serving client request. Pass
nulloptto disable timeout.
-
inline auto set_request_header_limit(optional<std::uint32_t> limit) & noexcept -> builder&#
Set the maximum size in bytes for reading client request headers.
- DESCRIPTION
Set the maximum size in bytes for reading client request headers. Pass
nulloptto disable headers size check. Default limit is 8KB.
-
inline auto set_request_body_limit(optional<std::uint64_t> limit) & noexcept -> builder&#
Set the maximum size in bytes for reading client request body.
- DESCRIPTION
Set the maximum size in bytes for reading client request body. Pass
nulloptto disable body size check. Default limit is 1MB.
-
template<typename F>
inline auto set_exception_handler(F &&f) & -> builder&# Set the exception handler to handle any exception thrown from the server.
- DESCRIPTION
Set the exception handler to handle any exception thrown from the server. If is not set by user, the
default_exception_handlerwill be used.
-
template<basic_fixed_string RoutePath, typename ...RouteServices, typename Handler>
inline auto serve(route_impl<RoutePath, std::tuple<RouteServices...>, Handler> route) & -> builder&# Add a
routeto the server.- DESCRIPTION
Add a
routeto the server. Note that no duplicateroutes are allowed.
-
template<basic_fixed_string Path, typename ...Services, typename ...Routes>
inline auto serve(scope_impl<Path, std::tuple<Services...>, std::tuple<Routes...>> scope) & -> builder&# Add all
routes from ascopeto the server.- DESCRIPTION
Add all
routes from ascopeto the server. Note that no duplicate routes are allowed.
-
inline auto build() -> http_server#
Create the
http_server.- DESCRIPTION
Create the
http_server. Note that current object is no longer usable after calling this function.
-
inline auto set_max_listen_connections(int num) & noexcept -> builder&#
-
inline auto max_listen_connections() const noexcept -> int#