Instrument Neutral Distributed Interface INDI 2.2.5
httplib::Server Class Reference

#include <httplib.h>

Public Types

enum class  HandlerResponse { Handled , Unhandled }
using Handler = std::function<void(const Request &, Response &)>
using ExceptionHandler
using HandlerWithResponse
using HandlerWithContentReader
using Expect100ContinueHandler

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_trusted_proxies (const std::vector< std::string > &proxies)
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_ {INVALID_SOCKET}
std::vector< std::string > trusted_proxies_
size_t keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT
time_t keep_alive_timeout_sec_ = CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND
time_t read_timeout_sec_ = CPPHTTPLIB_SERVER_READ_TIMEOUT_SECOND
time_t read_timeout_usec_ = CPPHTTPLIB_SERVER_READ_TIMEOUT_USECOND
time_t write_timeout_sec_ = CPPHTTPLIB_SERVER_WRITE_TIMEOUT_SECOND
time_t write_timeout_usec_ = CPPHTTPLIB_SERVER_WRITE_TIMEOUT_USECOND
time_t idle_interval_sec_ = CPPHTTPLIB_IDLE_INTERVAL_SECOND
time_t idle_interval_usec_ = CPPHTTPLIB_IDLE_INTERVAL_USECOND
size_t payload_max_length_ = CPPHTTPLIB_PAYLOAD_MAX_LENGTH

Detailed Description

Definition at line 1173 of file httplib.h.

Member Typedef Documentation

◆ ExceptionHandler

Initial value:
std::function<void(const Request &, Response &, std::exception_ptr ep)>

Definition at line 1178 of file httplib.h.

◆ Expect100ContinueHandler

Initial value:
std::function<int(const Request &, Response &)>

Definition at line 1192 of file httplib.h.

◆ Handler

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

Definition at line 1176 of file httplib.h.

◆ HandlerWithContentReader

Initial value:
std::function<void(
const Request &, Response &, const ContentReader &content_reader)>

Definition at line 1189 of file httplib.h.

◆ HandlerWithResponse

Initial value:
std::function<HandlerResponse(const Request &, Response &)>

Definition at line 1186 of file httplib.h.

Member Enumeration Documentation

◆ HandlerResponse

Enumerator
Handled 
Unhandled 

Definition at line 1181 of file httplib.h.

Constructor & Destructor Documentation

◆ Server()

httplib::Server::Server ( )
inline

Definition at line 10589 of file httplib.h.

◆ ~Server()

httplib::Server::~Server ( )
inlinevirtualdefault

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 10899 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 10889 of file httplib.h.

◆ decommission()

void httplib::Server::decommission ( )
inline

Definition at line 10945 of file httplib.h.

◆ Delete() [1/2]

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

Definition at line 10664 of file httplib.h.

◆ Delete() [2/2]

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

Definition at line 10670 of file httplib.h.

◆ Get()

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

Definition at line 10616 of file httplib.h.

◆ is_running()

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

Definition at line 10920 of file httplib.h.

◆ is_valid()

bool httplib::Server::is_valid ( ) const
inlinevirtual

Definition at line 12374 of file httplib.h.

◆ listen()

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

Definition at line 10914 of file httplib.h.

◆ listen_after_bind()

bool httplib::Server::listen_after_bind ( )
inline

Definition at line 10909 of file httplib.h.

◆ Options()

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

Definition at line 10678 of file httplib.h.

◆ Patch() [1/2]

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

Definition at line 10650 of file httplib.h.

◆ Patch() [2/2]

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

Definition at line 10656 of file httplib.h.

◆ Post() [1/2]

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

Definition at line 10622 of file httplib.h.

◆ Post() [2/2]

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

Definition at line 10628 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 )
inlineprotected

Definition at line 12116 of file httplib.h.

◆ Put() [1/2]

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

Definition at line 10636 of file httplib.h.

◆ Put() [2/2]

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

Definition at line 10642 of file httplib.h.

◆ remove_mount_point()

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

Definition at line 10706 of file httplib.h.

◆ set_address_family()

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

Definition at line 10806 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 10684 of file httplib.h.

◆ set_default_file_mimetype()

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

Definition at line 10727 of file httplib.h.

◆ set_default_headers()

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

Definition at line 10830 of file httplib.h.

◆ set_error_handler()

template<class ErrorHandlerFunc>
Server & httplib::Server::set_error_handler ( ErrorHandlerFunc && handler)
inline

Definition at line 1223 of file httplib.h.

◆ set_error_logger()

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

Definition at line 10787 of file httplib.h.

◆ set_exception_handler()

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

Definition at line 10757 of file httplib.h.

◆ set_expect_100_continue_handler()

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

Definition at line 10800 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 10720 of file httplib.h.

◆ set_file_request_handler()

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

Definition at line 10733 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 10836 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 2628 of file httplib.h.

◆ set_idle_interval() [2/2]

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

Definition at line 10876 of file httplib.h.

◆ set_ipv6_v6only()

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

Definition at line 10818 of file httplib.h.

◆ set_keep_alive_max_count()

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

Definition at line 10850 of file httplib.h.

◆ set_keep_alive_timeout()

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

Definition at line 10856 of file httplib.h.

◆ set_logger()

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

Definition at line 10781 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 10690 of file httplib.h.

◆ set_payload_max_length()

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

Definition at line 10883 of file httplib.h.

◆ set_post_routing_handler()

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

Definition at line 10769 of file httplib.h.

◆ set_pre_compression_logger()

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

Definition at line 10793 of file httplib.h.

◆ set_pre_request_handler()

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

Definition at line 10775 of file httplib.h.

◆ set_pre_routing_handler()

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

Definition at line 10763 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 2604 of file httplib.h.

◆ set_read_timeout() [2/2]

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

Definition at line 10862 of file httplib.h.

◆ set_socket_options()

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

Definition at line 10824 of file httplib.h.

◆ set_tcp_nodelay()

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

Definition at line 10812 of file httplib.h.

◆ set_trusted_proxies()

Server & httplib::Server::set_trusted_proxies ( const std::vector< std::string > & proxies)
inline

Definition at line 10844 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 2616 of file httplib.h.

◆ set_write_timeout() [2/2]

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

Definition at line 10869 of file httplib.h.

◆ stop()

void httplib::Server::stop ( )
inline

Definition at line 10933 of file httplib.h.

◆ wait_until_ready()

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

Definition at line 10925 of file httplib.h.

Member Data Documentation

◆ idle_interval_sec_

time_t httplib::Server::idle_interval_sec_ = CPPHTTPLIB_IDLE_INTERVAL_SECOND
protected

Definition at line 1300 of file httplib.h.

◆ idle_interval_usec_

time_t httplib::Server::idle_interval_usec_ = CPPHTTPLIB_IDLE_INTERVAL_USECOND
protected

Definition at line 1301 of file httplib.h.

◆ keep_alive_max_count_

size_t httplib::Server::keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT
protected

Definition at line 1294 of file httplib.h.

◆ keep_alive_timeout_sec_

time_t httplib::Server::keep_alive_timeout_sec_ = CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND
protected

Definition at line 1295 of file httplib.h.

◆ new_task_queue

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

Definition at line 1281 of file httplib.h.

◆ payload_max_length_

size_t httplib::Server::payload_max_length_ = CPPHTTPLIB_PAYLOAD_MAX_LENGTH
protected

Definition at line 1302 of file httplib.h.

◆ read_timeout_sec_

time_t httplib::Server::read_timeout_sec_ = CPPHTTPLIB_SERVER_READ_TIMEOUT_SECOND
protected

Definition at line 1296 of file httplib.h.

◆ read_timeout_usec_

time_t httplib::Server::read_timeout_usec_ = CPPHTTPLIB_SERVER_READ_TIMEOUT_USECOND
protected

Definition at line 1297 of file httplib.h.

◆ svr_sock_

std::atomic<socket_t> httplib::Server::svr_sock_ {INVALID_SOCKET}
protected

Definition at line 1290 of file httplib.h.

◆ trusted_proxies_

std::vector<std::string> httplib::Server::trusted_proxies_
protected

Definition at line 1292 of file httplib.h.

◆ write_timeout_sec_

time_t httplib::Server::write_timeout_sec_ = CPPHTTPLIB_SERVER_WRITE_TIMEOUT_SECOND
protected

Definition at line 1298 of file httplib.h.

◆ write_timeout_usec_

time_t httplib::Server::write_timeout_usec_ = CPPHTTPLIB_SERVER_WRITE_TIMEOUT_USECOND
protected

Definition at line 1299 of file httplib.h.


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