Goby3  3.1.5a
2024.05.23
httplib::Server Class Reference

#include <goby/util/thirdparty/cpp-httplib/httplib.h>

Public Types

enum  HandlerResponse { HandlerResponse::Handled, HandlerResponse::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
 
ServerGet (const std::string &pattern, Handler 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)
 
ServerPatch (const std::string &pattern, Handler handler)
 
ServerPatch (const std::string &pattern, HandlerWithContentReader handler)
 
ServerDelete (const std::string &pattern, Handler handler)
 
ServerDelete (const std::string &pattern, HandlerWithContentReader handler)
 
ServerOptions (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)
 
Serverset_file_extension_and_mimetype_mapping (const std::string &ext, const std::string &mime)
 
Serverset_default_file_mimetype (const std::string &mime)
 
Serverset_file_request_handler (Handler handler)
 
Serverset_error_handler (HandlerWithResponse handler)
 
Serverset_error_handler (Handler handler)
 
Serverset_exception_handler (ExceptionHandler handler)
 
Serverset_pre_routing_handler (HandlerWithResponse handler)
 
Serverset_post_routing_handler (Handler handler)
 
Serverset_expect_100_continue_handler (Expect100ContinueHandler handler)
 
Serverset_logger (Logger logger)
 
Serverset_address_family (int family)
 
Serverset_tcp_nodelay (bool on)
 
Serverset_socket_options (SocketOptions socket_options)
 
Serverset_default_headers (Headers headers)
 
Serverset_keep_alive_max_count (size_t count)
 
Serverset_keep_alive_timeout (time_t sec)
 
Serverset_read_timeout (time_t sec, time_t usec=0)
 
template<class Rep , class Period >
Serverset_read_timeout (const std::chrono::duration< Rep, Period > &duration)
 
Serverset_write_timeout (time_t sec, time_t usec=0)
 
template<class Rep , class Period >
Serverset_write_timeout (const std::chrono::duration< Rep, Period > &duration)
 
Serverset_idle_interval (time_t sec, time_t usec=0)
 
template<class Rep , class Period >
Serverset_idle_interval (const std::chrono::duration< Rep, Period > &duration)
 
Serverset_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 ()
 

Public Attributes

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

Protected Member Functions

bool process_request (Stream &strm, bool close_connection, bool &connection_closed, const std::function< void(Request &)> &setup_request)
 

Protected Attributes

std::atomic< socket_tsvr_sock_ {INVALID_SOCKET}
 
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_READ_TIMEOUT_SECOND
 
time_t read_timeout_usec_ = CPPHTTPLIB_READ_TIMEOUT_USECOND
 
time_t write_timeout_sec_ = CPPHTTPLIB_WRITE_TIMEOUT_SECOND
 
time_t write_timeout_usec_ = CPPHTTPLIB_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 771 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 776 of file httplib.h.

◆ Expect100ContinueHandler

Definition at line 788 of file httplib.h.

◆ Handler

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

Definition at line 774 of file httplib.h.

◆ HandlerWithContentReader

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

Definition at line 786 of file httplib.h.

◆ HandlerWithResponse

Definition at line 783 of file httplib.h.

Member Enumeration Documentation

◆ HandlerResponse

Enumerator
Handled 
Unhandled 

Definition at line 778 of file httplib.h.

Constructor & Destructor Documentation

◆ Server()

httplib::Server::Server ( )
inline

Definition at line 6196 of file httplib.h.

◆ ~Server()

httplib::Server::~Server ( )
inlinevirtual

Definition at line 6204 of file httplib.h.

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 6449 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 6443 of file httplib.h.

◆ Delete() [1/2]

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

Definition at line 6263 of file httplib.h.

◆ Delete() [2/2]

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

Definition at line 6269 of file httplib.h.

◆ Get()

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

Definition at line 6218 of file httplib.h.

◆ is_running()

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

Definition at line 6466 of file httplib.h.

◆ is_valid()

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

Definition at line 7521 of file httplib.h.

◆ listen()

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

Definition at line 6460 of file httplib.h.

◆ listen_after_bind()

bool httplib::Server::listen_after_bind ( )
inline

Definition at line 6454 of file httplib.h.

◆ Options()

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

Definition at line 6276 of file httplib.h.

◆ Patch() [1/2]

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

Definition at line 6250 of file httplib.h.

◆ Patch() [2/2]

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

Definition at line 6256 of file httplib.h.

◆ Post() [1/2]

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

Definition at line 6224 of file httplib.h.

◆ Post() [2/2]

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

Definition at line 6230 of file httplib.h.

◆ process_request()

bool httplib::Server::process_request ( Stream strm,
bool  close_connection,
bool connection_closed,
const std::function< void(Request &)> &  setup_request 
)
inlineprotected

Definition at line 7353 of file httplib.h.

◆ Put() [1/2]

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

Definition at line 6237 of file httplib.h.

◆ Put() [2/2]

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

Definition at line 6243 of file httplib.h.

◆ remove_mount_point()

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

Definition at line 6302 of file httplib.h.

◆ set_address_family()

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

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

◆ set_default_file_mimetype()

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

Definition at line 6322 of file httplib.h.

◆ set_default_headers()

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

Definition at line 6398 of file httplib.h.

◆ set_error_handler() [1/2]

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

Definition at line 6340 of file httplib.h.

◆ set_error_handler() [2/2]

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

Definition at line 6334 of file httplib.h.

◆ set_exception_handler()

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

Definition at line 6350 of file httplib.h.

◆ set_expect_100_continue_handler()

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

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

◆ set_file_request_handler()

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

Definition at line 6328 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 1825 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 6430 of file httplib.h.

◆ set_keep_alive_max_count()

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

Definition at line 6404 of file httplib.h.

◆ set_keep_alive_timeout()

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

Definition at line 6410 of file httplib.h.

◆ set_logger()

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

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

◆ set_payload_max_length()

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

Definition at line 6437 of file httplib.h.

◆ set_post_routing_handler()

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

Definition at line 6362 of file httplib.h.

◆ set_pre_routing_handler()

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

Definition at line 6356 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 1809 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 6416 of file httplib.h.

◆ set_socket_options()

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

Definition at line 6392 of file httplib.h.

◆ set_tcp_nodelay()

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

Definition at line 6386 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 1817 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 6423 of file httplib.h.

◆ stop()

void httplib::Server::stop ( )
inline

Definition at line 6473 of file httplib.h.

◆ wait_until_ready()

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

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

◆ idle_interval_usec_

time_t httplib::Server::idle_interval_usec_ = CPPHTTPLIB_IDLE_INTERVAL_USECOND
protected

Definition at line 872 of file httplib.h.

◆ keep_alive_max_count_

size_t httplib::Server::keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT
protected

Definition at line 865 of file httplib.h.

◆ keep_alive_timeout_sec_

time_t httplib::Server::keep_alive_timeout_sec_ = CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND
protected

Definition at line 866 of file httplib.h.

◆ new_task_queue

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

Definition at line 858 of file httplib.h.

◆ payload_max_length_

size_t httplib::Server::payload_max_length_ = CPPHTTPLIB_PAYLOAD_MAX_LENGTH
protected

Definition at line 873 of file httplib.h.

◆ read_timeout_sec_

time_t httplib::Server::read_timeout_sec_ = CPPHTTPLIB_READ_TIMEOUT_SECOND
protected

Definition at line 867 of file httplib.h.

◆ read_timeout_usec_

time_t httplib::Server::read_timeout_usec_ = CPPHTTPLIB_READ_TIMEOUT_USECOND
protected

Definition at line 868 of file httplib.h.

◆ svr_sock_

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

Definition at line 864 of file httplib.h.

◆ write_timeout_sec_

time_t httplib::Server::write_timeout_sec_ = CPPHTTPLIB_WRITE_TIMEOUT_SECOND
protected

Definition at line 869 of file httplib.h.

◆ write_timeout_usec_

time_t httplib::Server::write_timeout_usec_ = CPPHTTPLIB_WRITE_TIMEOUT_USECOND
protected

Definition at line 870 of file httplib.h.


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