D++ (DPP)
C++ Discord API Bot Library
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 &e)>
 
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 char *pattern, Handler handler)
 
ServerGet (const char *pattern, size_t pattern_len, Handler handler)
 
ServerPost (const char *pattern, Handler handler)
 
ServerPost (const char *pattern, size_t pattern_len, Handler handler)
 
ServerPost (const char *pattern, HandlerWithContentReader handler)
 
ServerPost (const char *pattern, size_t pattern_len, HandlerWithContentReader handler)
 
ServerPut (const char *pattern, Handler handler)
 
ServerPut (const char *pattern, size_t pattern_len, Handler handler)
 
ServerPut (const char *pattern, HandlerWithContentReader handler)
 
ServerPut (const char *pattern, size_t pattern_len, HandlerWithContentReader handler)
 
ServerPatch (const char *pattern, Handler handler)
 
ServerPatch (const char *pattern, size_t pattern_len, Handler handler)
 
ServerPatch (const char *pattern, HandlerWithContentReader handler)
 
ServerPatch (const char *pattern, size_t pattern_len, HandlerWithContentReader handler)
 
ServerDelete (const char *pattern, Handler handler)
 
ServerDelete (const char *pattern, size_t pattern_len, Handler handler)
 
ServerDelete (const char *pattern, HandlerWithContentReader handler)
 
ServerDelete (const char *pattern, size_t pattern_len, HandlerWithContentReader handler)
 
ServerOptions (const char *pattern, Handler handler)
 
ServerOptions (const char *pattern, size_t pattern_len, Handler handler)
 
bool set_base_dir (const char *dir, const char *mount_point=nullptr)
 
bool set_mount_point (const char *mount_point, const char *dir, Headers headers=Headers())
 
bool remove_mount_point (const char *mount_point)
 
Serverset_file_extension_and_mimetype_mapping (const char *ext, const char *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_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 char *host, int port, int socket_flags=0)
 
int bind_to_any_port (const char *host, int socket_flags=0)
 
bool listen_after_bind ()
 
bool listen (const char *host, int port, int socket_flags=0)
 
bool is_running () 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_t > svr_sock_
 
size_t keep_alive_max_count_ = 5
 
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)())
 

Member Typedef Documentation

◆ ExceptionHandler

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

◆ Expect100ContinueHandler

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

◆ Handler

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

◆ HandlerWithContentReader

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

◆ HandlerWithResponse

Member Enumeration Documentation

◆ HandlerResponse

Enumerator
Handled 
Unhandled 

Constructor & Destructor Documentation

◆ Server()

httplib::Server::Server ( )

◆ ~Server()

virtual httplib::Server::~Server ( )
virtual

Member Function Documentation

◆ bind_to_any_port()

int httplib::Server::bind_to_any_port ( const char *  host,
int  socket_flags = 0 
)

◆ bind_to_port()

bool httplib::Server::bind_to_port ( const char *  host,
int  port,
int  socket_flags = 0 
)

◆ Delete() [1/4]

Server & httplib::Server::Delete ( const char *  pattern,
Handler  handler 
)

◆ Delete() [2/4]

Server & httplib::Server::Delete ( const char *  pattern,
HandlerWithContentReader  handler 
)

◆ Delete() [3/4]

Server & httplib::Server::Delete ( const char *  pattern,
size_t  pattern_len,
Handler  handler 
)

◆ Delete() [4/4]

Server & httplib::Server::Delete ( const char *  pattern,
size_t  pattern_len,
HandlerWithContentReader  handler 
)

◆ Get() [1/2]

Server & httplib::Server::Get ( const char *  pattern,
Handler  handler 
)

◆ Get() [2/2]

Server & httplib::Server::Get ( const char *  pattern,
size_t  pattern_len,
Handler  handler 
)

◆ is_running()

bool httplib::Server::is_running ( ) const

◆ is_valid()

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

◆ listen()

bool httplib::Server::listen ( const char *  host,
int  port,
int  socket_flags = 0 
)

◆ listen_after_bind()

bool httplib::Server::listen_after_bind ( )

◆ Options() [1/2]

Server & httplib::Server::Options ( const char *  pattern,
Handler  handler 
)

◆ Options() [2/2]

Server & httplib::Server::Options ( const char *  pattern,
size_t  pattern_len,
Handler  handler 
)

◆ Patch() [1/4]

Server & httplib::Server::Patch ( const char *  pattern,
Handler  handler 
)

◆ Patch() [2/4]

Server & httplib::Server::Patch ( const char *  pattern,
HandlerWithContentReader  handler 
)

◆ Patch() [3/4]

Server & httplib::Server::Patch ( const char *  pattern,
size_t  pattern_len,
Handler  handler 
)

◆ Patch() [4/4]

Server & httplib::Server::Patch ( const char *  pattern,
size_t  pattern_len,
HandlerWithContentReader  handler 
)

◆ Post() [1/4]

Server & httplib::Server::Post ( const char *  pattern,
Handler  handler 
)

◆ Post() [2/4]

Server & httplib::Server::Post ( const char *  pattern,
HandlerWithContentReader  handler 
)

◆ Post() [3/4]

Server & httplib::Server::Post ( const char *  pattern,
size_t  pattern_len,
Handler  handler 
)

◆ Post() [4/4]

Server & httplib::Server::Post ( const char *  pattern,
size_t  pattern_len,
HandlerWithContentReader  handler 
)

◆ process_request()

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

◆ Put() [1/4]

Server & httplib::Server::Put ( const char *  pattern,
Handler  handler 
)

◆ Put() [2/4]

Server & httplib::Server::Put ( const char *  pattern,
HandlerWithContentReader  handler 
)

◆ Put() [3/4]

Server & httplib::Server::Put ( const char *  pattern,
size_t  pattern_len,
Handler  handler 
)

◆ Put() [4/4]

Server & httplib::Server::Put ( const char *  pattern,
size_t  pattern_len,
HandlerWithContentReader  handler 
)

◆ remove_mount_point()

bool httplib::Server::remove_mount_point ( const char *  mount_point)

◆ set_address_family()

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

◆ set_base_dir()

bool httplib::Server::set_base_dir ( const char *  dir,
const char *  mount_point = nullptr 
)

◆ set_error_handler() [1/2]

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

◆ set_error_handler() [2/2]

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

◆ set_exception_handler()

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

◆ set_expect_100_continue_handler()

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

◆ set_file_extension_and_mimetype_mapping()

Server & httplib::Server::set_file_extension_and_mimetype_mapping ( const char *  ext,
const char *  mime 
)

◆ set_file_request_handler()

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

◆ set_idle_interval() [1/2]

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

◆ set_idle_interval() [2/2]

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

◆ set_keep_alive_max_count()

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

◆ set_keep_alive_timeout()

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

◆ set_logger()

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

◆ set_mount_point()

bool httplib::Server::set_mount_point ( const char *  mount_point,
const char *  dir,
Headers  headers = Headers() 
)

◆ set_payload_max_length()

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

◆ set_post_routing_handler()

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

◆ set_pre_routing_handler()

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

◆ set_read_timeout() [1/2]

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

◆ set_read_timeout() [2/2]

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

◆ set_socket_options()

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

◆ set_tcp_nodelay()

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

◆ set_write_timeout() [1/2]

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

◆ set_write_timeout() [2/2]

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

◆ stop()

void httplib::Server::stop ( )

Member Data Documentation

◆ idle_interval_sec_

time_t httplib::Server::idle_interval_sec_ = 0
protected

◆ idle_interval_usec_

time_t httplib::Server::idle_interval_usec_ = 0
protected

◆ keep_alive_max_count_

size_t httplib::Server::keep_alive_max_count_ = 5
protected

◆ keep_alive_timeout_sec_

time_t httplib::Server::keep_alive_timeout_sec_ = 5
protected

◆ new_task_queue

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

◆ payload_max_length_

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

◆ read_timeout_sec_

time_t httplib::Server::read_timeout_sec_ = 5
protected

◆ read_timeout_usec_

time_t httplib::Server::read_timeout_usec_ = 0
protected

◆ svr_sock_

std::atomic<socket_t> httplib::Server::svr_sock_
protected

◆ write_timeout_sec_

time_t httplib::Server::write_timeout_sec_ = 5
protected

◆ write_timeout_usec_

time_t httplib::Server::write_timeout_usec_ = 0
protected
D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0