pion
5.0.6
|
#include <server.hpp>
Inherits pion::tcp::server.
Inherited by pion::http::plugin_server.
Public Types | |
typedef boost::function2< void, http::request_ptr &, tcp::connection_ptr & > | request_handler_t |
type of function that is used to handle requests | |
typedef boost::function3< void, http::request_ptr &, tcp::connection_ptr &, const std::string & > | error_handler_t |
handler for requests that result in "500 Server Error" | |
Public Member Functions | |
virtual | ~server () |
default destructor | |
server (const unsigned int tcp_port=0) | |
server (const boost::asio::ip::tcp::endpoint &endpoint) | |
server (scheduler &sched, const unsigned int tcp_port=0) | |
server (scheduler &sched, const boost::asio::ip::tcp::endpoint &endpoint) | |
void | add_resource (const std::string &resource, request_handler_t request_handler) |
void | remove_resource (const std::string &resource) |
void | add_redirect (const std::string &requested_resource, const std::string &new_resource) |
void | set_bad_request_handler (request_handler_t h) |
sets the function that handles bad HTTP requests | |
void | set_not_found_handler (request_handler_t h) |
sets the function that handles requests which match no other web services | |
void | set_error_handler (error_handler_t h) |
sets the function that handles requests which match no other web services | |
virtual void | clear (void) |
clears the collection of resources recognized by the HTTP server | |
void | set_authentication (http::auth_ptr auth) |
void | set_max_content_length (std::size_t n) |
sets the maximum length for HTTP request payload content | |
![]() | |
void | start (void) |
starts listening for new connections | |
void | stop (bool wait_until_finished=false) |
void | join (void) |
the calling thread will sleep until the server has stopped listening for connections | |
void | set_ssl_key_file (const std::string &pem_key_file) |
std::size_t | get_connections (void) const |
returns the number of active tcp connections | |
unsigned int | get_port (void) const |
returns tcp port number that the server listens for connections on | |
void | set_port (unsigned int p) |
sets tcp port number that the server listens for connections on | |
boost::asio::ip::address | get_address (void) const |
returns IP address that the server listens for connections on | |
void | set_address (const boost::asio::ip::address &addr) |
sets IP address that the server listens for connections on | |
const boost::asio::ip::tcp::endpoint & | get_endpoint (void) const |
returns tcp endpoint that the server listens for connections on | |
void | set_endpoint (const boost::asio::ip::tcp::endpoint &ep) |
sets tcp endpoint that the server listens for connections on | |
bool | get_ssl_flag (void) const |
returns true if the server uses SSL to encrypt connections | |
void | set_ssl_flag (bool b=true) |
sets value of SSL flag (true if the server uses SSL to encrypt connections) | |
connection::ssl_context_type & | get_ssl_context_type (void) |
returns the SSL context for configuration | |
bool | is_listening (void) const |
returns true if the server is listening for connections | |
void | set_logger (logger log_ptr) |
sets the logger to be used | |
logger | get_logger (void) |
returns the logger currently in use | |
boost::asio::ip::tcp::acceptor & | get_acceptor (void) |
returns mutable reference to the TCP connection acceptor | |
const boost::asio::ip::tcp::acceptor & | get_acceptor (void) const |
returns const reference to the TCP connection acceptor | |
Static Public Member Functions | |
static std::string | strip_trailing_slash (const std::string &str) |
static void | handle_bad_request (http::request_ptr &http_request_ptr, tcp::connection_ptr &tcp_conn) |
static void | handle_not_found_request (http::request_ptr &http_request_ptr, tcp::connection_ptr &tcp_conn) |
static void | handle_server_error (http::request_ptr &http_request_ptr, tcp::connection_ptr &tcp_conn, const std::string &error_msg) |
static void | handle_forbidden_request (http::request_ptr &http_request_ptr, tcp::connection_ptr &tcp_conn, const std::string &error_msg) |
static void | handle_method_not_allowed (http::request_ptr &http_request_ptr, tcp::connection_ptr &tcp_conn, const std::string &allowed_methods="") |
Protected Member Functions | |
virtual void | handle_connection (tcp::connection_ptr &tcp_conn) |
virtual void | handle_request (http::request_ptr &http_request_ptr, tcp::connection_ptr &tcp_conn, const boost::system::error_code &ec) |
virtual bool | find_request_handler (const std::string &resource, request_handler_t &request_handler) const |
![]() | |
server (const unsigned int tcp_port) | |
server (const boost::asio::ip::tcp::endpoint &endpoint) | |
server (scheduler &sched, const unsigned int tcp_port=0) | |
server (scheduler &sched, const boost::asio::ip::tcp::endpoint &endpoint) | |
virtual void | before_starting (void) |
called before the TCP server starts listening for new connections | |
virtual void | after_stopping (void) |
called after the TCP server has stopped listing for new connections | |
boost::asio::io_service & | get_io_service (void) |
returns an async I/O service used to schedule work | |
Additional Inherited Members | |
![]() | |
logger | m_logger |
primary logging interface used by this class | |
server: a server that handles HTTP connections
Definition at line 36 of file server.hpp.
|
inlineexplicit |
creates a new server object
tcp_port | port number used to listen for new connections (IPv4) |
Definition at line 58 of file server.hpp.
|
inlineexplicit |
creates a new server object
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
Definition at line 73 of file server.hpp.
|
inlineexplicit |
creates a new server object
sched | the scheduler that will be used to manage worker threads |
tcp_port | port number used to listen for new connections (IPv4) |
Definition at line 89 of file server.hpp.
|
inline |
creates a new server object
sched | the scheduler that will be used to manage worker threads |
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
Definition at line 105 of file server.hpp.
void pion::http::server::add_redirect | ( | const std::string & | requested_resource, |
const std::string & | new_resource | ||
) |
adds a new resource redirection to the HTTP server
requested_resource | the resource name or uri-stem that will be redirected |
new_resource | the resource that requested_resource will be redirected to |
Definition at line 177 of file http_server.cpp.
References pion::tcp::server::m_logger, and strip_trailing_slash().
void pion::http::server::add_resource | ( | const std::string & | resource, |
request_handler_t | request_handler | ||
) |
adds a new web service to the HTTP server
resource | the resource name or uri-stem to bind to the handler |
request_handler | function used to handle requests to the resource |
Definition at line 160 of file http_server.cpp.
References pion::tcp::server::m_logger, and strip_trailing_slash().
Referenced by pion::http::plugin_server::add_service(), and pion::http::plugin_server::load_service().
|
protectedvirtual |
searches for the appropriate request handler to use for a given resource
resource | the name of the resource to search for |
request_handler | function that can handle requests for this resource |
Definition at line 134 of file http_server.cpp.
Referenced by handle_request().
|
static |
used to send responses when a bad HTTP request is made
http_request_ptr | the new HTTP request to handle |
tcp_conn | the TCP connection that has the new request |
Definition at line 187 of file http_server.cpp.
References pion::http::response_writer::create(), and pion::tcp::connection::finish().
|
protectedvirtual |
handles a new TCP connection
tcp_conn | the new TCP connection to handle |
Reimplemented from pion::tcp::server.
Definition at line 29 of file http_server.cpp.
References pion::http::request_reader::create(), and handle_request().
|
static |
used to send responses when a request is forbidden
http_request_ptr | the new HTTP request to handle |
tcp_conn | the TCP connection that has the new request |
error_msg | message that explains what went wrong |
Definition at line 250 of file http_server.cpp.
References pion::http::response_writer::create(), pion::tcp::connection::finish(), and pion::algorithm::xml_encode().
|
static |
used to send responses when a method is not allowed
http_request_ptr | the new HTTP request to handle |
tcp_conn | the TCP connection that has the new request |
allowed_methods | optional comma separated list of allowed methods |
Definition at line 277 of file http_server.cpp.
References pion::http::response_writer::create(), pion::tcp::connection::finish(), and pion::algorithm::xml_encode().
|
static |
used to send responses when no web services can handle the request
http_request_ptr | the new HTTP request to handle |
tcp_conn | the TCP connection that has the new request |
Definition at line 205 of file http_server.cpp.
References pion::http::response_writer::create(), pion::tcp::connection::finish(), and pion::algorithm::xml_encode().
|
protectedvirtual |
handles a new HTTP request
http_request_ptr | the HTTP request to handle |
tcp_conn | TCP connection containing a new request |
ec | error_code contains additional information for parsing errors |
Definition at line 38 of file http_server.cpp.
References find_request_handler(), pion::http::parser::get_error_category(), pion::tcp::server::get_port(), pion::tcp::server::m_logger, and strip_trailing_slash().
Referenced by handle_connection().
|
static |
used to send responses when a server error occurs
http_request_ptr | the new HTTP request to handle |
tcp_conn | the TCP connection that has the new request |
error_msg | message that explains what went wrong |
Definition at line 227 of file http_server.cpp.
References pion::http::response_writer::create(), pion::tcp::connection::finish(), and pion::algorithm::xml_encode().
void pion::http::server::remove_resource | ( | const std::string & | resource | ) |
removes a web service from the HTTP server
resource | the resource name or uri-stem to remove |
Definition at line 169 of file http_server.cpp.
References pion::tcp::server::m_logger, and strip_trailing_slash().
|
inline |
sets the handler object for authentication verification processing
Definition at line 221 of file server.hpp.
Referenced by pion::http::plugin_server::load_service_config().
|
inlinestatic |
strips trailing slash from a string, if one exists
str | the original string |
Definition at line 160 of file server.hpp.
Referenced by pion::http::auth::add_permit(), add_redirect(), add_resource(), pion::http::auth::add_restrict(), pion::http::plugin_server::add_service(), handle_request(), pion::http::plugin_server::load_service(), pion::http::auth::need_authentication(), pion::http::cookie_auth::process_login(), remove_resource(), and pion::http::plugin_server::set_service_option().