Server Class Reference

#include <RobotAPI/libraries/armem/server/ltm/detail/mixins/util/httplib.h>

Public Types

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

Public Member Functions

int bind_to_any_port (const std::string &host, int socket_flags=0)
 
bool bind_to_port (const std::string &host, int port, int socket_flags=0)
 
void decommission ()
 
ServerDelete (const std::string &pattern, Handler handler)
 
ServerDelete (const std::string &pattern, HandlerWithContentReader handler)
 
ServerGet (const std::string &pattern, Handler handler)
 
bool is_running () const
 
virtual bool is_valid () const
 
bool listen (const std::string &host, int port, int socket_flags=0)
 
bool listen_after_bind ()
 
ServerOptions (const std::string &pattern, Handler handler)
 
ServerPatch (const std::string &pattern, Handler handler)
 
ServerPatch (const std::string &pattern, HandlerWithContentReader handler)
 
ServerPost (const std::string &pattern, Handler handler)
 
ServerPost (const std::string &pattern, HandlerWithContentReader handler)
 
ServerPut (const std::string &pattern, Handler handler)
 
ServerPut (const std::string &pattern, HandlerWithContentReader handler)
 
bool remove_mount_point (const std::string &mount_point)
 
 Server ()
 
Serverset_address_family (int family)
 
bool set_base_dir (const std::string &dir, const std::string &mount_point=std::string())
 
Serverset_default_file_mimetype (const std::string &mime)
 
Serverset_default_headers (Headers headers)
 
template<class ErrorHandlerFunc >
Serverset_error_handler (ErrorHandlerFunc &&handler)
 
Serverset_exception_handler (ExceptionHandler handler)
 
Serverset_expect_100_continue_handler (Expect100ContinueHandler handler)
 
Serverset_file_extension_and_mimetype_mapping (const std::string &ext, const std::string &mime)
 
Serverset_file_request_handler (Handler handler)
 
Serverset_header_writer (std::function< ssize_t(Stream &, Headers &)> const &writer)
 
template<class Rep , class Period >
Serverset_idle_interval (const std::chrono::duration< Rep, Period > &duration)
 
Serverset_idle_interval (time_t sec, time_t usec=0)
 
Serverset_ipv6_v6only (bool on)
 
Serverset_keep_alive_max_count (size_t count)
 
Serverset_keep_alive_timeout (time_t sec)
 
Serverset_logger (Logger logger)
 
bool set_mount_point (const std::string &mount_point, const std::string &dir, Headers headers=Headers())
 
Serverset_payload_max_length (size_t length)
 
Serverset_post_routing_handler (Handler handler)
 
Serverset_pre_routing_handler (HandlerWithResponse handler)
 
template<class Rep , class Period >
Serverset_read_timeout (const std::chrono::duration< Rep, Period > &duration)
 
Serverset_read_timeout (time_t sec, time_t usec=0)
 
Serverset_socket_options (SocketOptions socket_options)
 
Serverset_tcp_nodelay (bool on)
 
template<class Rep , class Period >
Serverset_write_timeout (const std::chrono::duration< Rep, Period > &duration)
 
Serverset_write_timeout (time_t sec, time_t usec=0)
 
void stop ()
 
void wait_until_ready () const
 
virtual ~Server ()
 

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

time_t idle_interval_sec_ = CPPHTTPLIB_IDLE_INTERVAL_SECOND
 
time_t idle_interval_usec_ = CPPHTTPLIB_IDLE_INTERVAL_USECOND
 
size_t keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT
 
time_t keep_alive_timeout_sec_ = CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND
 
size_t payload_max_length_ = CPPHTTPLIB_PAYLOAD_MAX_LENGTH
 
time_t read_timeout_sec_ = CPPHTTPLIB_SERVER_READ_TIMEOUT_SECOND
 
time_t read_timeout_usec_ = CPPHTTPLIB_SERVER_READ_TIMEOUT_USECOND
 
std::atomic< socket_tsvr_sock_ {INVALID_SOCKET}
 
time_t write_timeout_sec_ = CPPHTTPLIB_SERVER_WRITE_TIMEOUT_SECOND
 
time_t write_timeout_usec_ = CPPHTTPLIB_SERVER_WRITE_TIMEOUT_USECOND
 

Detailed Description

Definition at line 917 of file httplib.h.

Member Typedef Documentation

◆ ExceptionHandler

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

Definition at line 922 of file httplib.h.

◆ Expect100ContinueHandler

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

Definition at line 935 of file httplib.h.

◆ Handler

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

Definition at line 919 of file httplib.h.

◆ HandlerWithContentReader

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

Definition at line 932 of file httplib.h.

◆ HandlerWithResponse

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

Definition at line 929 of file httplib.h.

Member Enumeration Documentation

◆ HandlerResponse

enum HandlerResponse
strong
Enumerator
Handled 
Unhandled 

Definition at line 924 of file httplib.h.

Constructor & Destructor Documentation

◆ Server()

Server ( )
inline

Definition at line 6083 of file httplib.h.

◆ ~Server()

~Server ( )
inlinevirtualdefault

Member Function Documentation

◆ bind_to_any_port()

int bind_to_any_port ( const std::string &  host,
int  socket_flags = 0 
)
inline

Definition at line 6316 of file httplib.h.

◆ bind_to_port()

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

Definition at line 6310 of file httplib.h.

+ Here is the caller graph for this function:

◆ decommission()

void decommission ( )
inline

Definition at line 6347 of file httplib.h.

◆ Delete() [1/2]

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

Definition at line 6143 of file httplib.h.

◆ Delete() [2/2]

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

Definition at line 6148 of file httplib.h.

◆ Get()

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

Definition at line 6102 of file httplib.h.

◆ is_running()

bool is_running ( ) const
inline

Definition at line 6329 of file httplib.h.

◆ is_valid()

bool is_valid ( ) const
inlinevirtual

Definition at line 7217 of file httplib.h.

◆ listen()

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

Definition at line 6324 of file httplib.h.

+ Here is the call graph for this function:

◆ listen_after_bind()

bool listen_after_bind ( )
inline

Definition at line 6322 of file httplib.h.

◆ Options()

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

Definition at line 6155 of file httplib.h.

◆ Patch() [1/2]

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

Definition at line 6131 of file httplib.h.

◆ Patch() [2/2]

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

Definition at line 6136 of file httplib.h.

◆ Post() [1/2]

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

Definition at line 6107 of file httplib.h.

◆ Post() [2/2]

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

Definition at line 6112 of file httplib.h.

◆ process_request()

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

Definition at line 7040 of file httplib.h.

+ Here is the call graph for this function:

◆ Put() [1/2]

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

Definition at line 6119 of file httplib.h.

◆ Put() [2/2]

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

Definition at line 6124 of file httplib.h.

◆ remove_mount_point()

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

Definition at line 6178 of file httplib.h.

◆ set_address_family()

Server & set_address_family ( int  family)
inline

Definition at line 6246 of file httplib.h.

◆ set_base_dir()

bool set_base_dir ( const std::string &  dir,
const std::string &  mount_point = std::string() 
)
inline

Definition at line 6160 of file httplib.h.

+ Here is the call graph for this function:

◆ set_default_file_mimetype()

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

Definition at line 6195 of file httplib.h.

◆ set_default_headers()

Server & set_default_headers ( Headers  headers)
inline

Definition at line 6266 of file httplib.h.

◆ set_error_handler()

Server& set_error_handler ( ErrorHandlerFunc &&  handler)
inline

Definition at line 965 of file httplib.h.

◆ set_exception_handler()

Server & set_exception_handler ( ExceptionHandler  handler)
inline

Definition at line 6220 of file httplib.h.

◆ set_expect_100_continue_handler()

Server & set_expect_100_continue_handler ( Expect100ContinueHandler  handler)
inline

Definition at line 6241 of file httplib.h.

◆ set_file_extension_and_mimetype_mapping()

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

Definition at line 6189 of file httplib.h.

◆ set_file_request_handler()

Server & set_file_request_handler ( Handler  handler)
inline

Definition at line 6200 of file httplib.h.

◆ set_header_writer()

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

Definition at line 6271 of file httplib.h.

◆ set_idle_interval() [1/2]

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

Definition at line 2160 of file httplib.h.

+ Here is the call graph for this function:

◆ set_idle_interval() [2/2]

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

Definition at line 6299 of file httplib.h.

+ Here is the caller graph for this function:

◆ set_ipv6_v6only()

Server & set_ipv6_v6only ( bool  on)
inline

Definition at line 6256 of file httplib.h.

◆ set_keep_alive_max_count()

Server & set_keep_alive_max_count ( size_t  count)
inline

Definition at line 6277 of file httplib.h.

◆ set_keep_alive_timeout()

Server & set_keep_alive_timeout ( time_t  sec)
inline

Definition at line 6282 of file httplib.h.

◆ set_logger()

Server & set_logger ( Logger  logger)
inline

Definition at line 6235 of file httplib.h.

◆ set_mount_point()

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

Definition at line 6165 of file httplib.h.

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

◆ set_payload_max_length()

Server & set_payload_max_length ( size_t  length)
inline

Definition at line 6305 of file httplib.h.

◆ set_post_routing_handler()

Server & set_post_routing_handler ( Handler  handler)
inline

Definition at line 6230 of file httplib.h.

◆ set_pre_routing_handler()

Server & set_pre_routing_handler ( HandlerWithResponse  handler)
inline

Definition at line 6225 of file httplib.h.

◆ set_read_timeout() [1/2]

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

Definition at line 2144 of file httplib.h.

+ Here is the call graph for this function:

◆ set_read_timeout() [2/2]

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

Definition at line 6287 of file httplib.h.

+ Here is the caller graph for this function:

◆ set_socket_options()

Server & set_socket_options ( SocketOptions  socket_options)
inline

Definition at line 6261 of file httplib.h.

◆ set_tcp_nodelay()

Server & set_tcp_nodelay ( bool  on)
inline

Definition at line 6251 of file httplib.h.

◆ set_write_timeout() [1/2]

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

Definition at line 2152 of file httplib.h.

+ Here is the call graph for this function:

◆ set_write_timeout() [2/2]

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

Definition at line 6293 of file httplib.h.

+ Here is the caller graph for this function:

◆ stop()

void stop ( )
inline

Definition at line 6337 of file httplib.h.

+ Here is the call graph for this function:

◆ wait_until_ready()

void wait_until_ready ( ) const
inline

Definition at line 6331 of file httplib.h.

Member Data Documentation

◆ idle_interval_sec_

time_t idle_interval_sec_ = CPPHTTPLIB_IDLE_INTERVAL_SECOND
protected

Definition at line 1031 of file httplib.h.

◆ idle_interval_usec_

time_t idle_interval_usec_ = CPPHTTPLIB_IDLE_INTERVAL_USECOND
protected

Definition at line 1032 of file httplib.h.

◆ keep_alive_max_count_

size_t keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT
protected

Definition at line 1025 of file httplib.h.

◆ keep_alive_timeout_sec_

time_t keep_alive_timeout_sec_ = CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND
protected

Definition at line 1026 of file httplib.h.

◆ new_task_queue

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

Definition at line 1015 of file httplib.h.

◆ payload_max_length_

size_t payload_max_length_ = CPPHTTPLIB_PAYLOAD_MAX_LENGTH
protected

Definition at line 1033 of file httplib.h.

◆ read_timeout_sec_

time_t read_timeout_sec_ = CPPHTTPLIB_SERVER_READ_TIMEOUT_SECOND
protected

Definition at line 1027 of file httplib.h.

◆ read_timeout_usec_

time_t read_timeout_usec_ = CPPHTTPLIB_SERVER_READ_TIMEOUT_USECOND
protected

Definition at line 1028 of file httplib.h.

◆ svr_sock_

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

Definition at line 1024 of file httplib.h.

◆ write_timeout_sec_

time_t write_timeout_sec_ = CPPHTTPLIB_SERVER_WRITE_TIMEOUT_SECOND
protected

Definition at line 1029 of file httplib.h.

◆ write_timeout_usec_

time_t write_timeout_usec_ = CPPHTTPLIB_SERVER_WRITE_TIMEOUT_USECOND
protected

Definition at line 1030 of file httplib.h.


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