PionNetworkLibrary
|
#include <server.hpp>
Public Types | |
typedef boost::function2< void, const http::request_ptr &, const tcp::connection_ptr & > | request_handler_t |
type of function that is used to handle requests More... | |
typedef boost::function3< void, const http::request_ptr &, const tcp::connection_ptr &, const std::string & > | error_handler_t |
handler for requests that result in "500 Server Error" More... | |
Public Member Functions | |
virtual | ~server () |
default destructor More... | |
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 More... | |
void | set_not_found_handler (request_handler_t h) |
sets the function that handles requests which match no other web services More... | |
void | set_error_handler (error_handler_t h) |
sets the function that handles requests which match no other web services More... | |
virtual void | clear (void) |
clears the collection of resources recognized by the HTTP server More... | |
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 More... | |
Public Member Functions inherited from pion::tcp::server | |
void | start (void) |
starts listening for new connections More... | |
void | stop (bool wait_until_finished=false) |
void | join (void) |
the calling thread will sleep until the server has stopped listening for connections More... | |
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 More... | |
unsigned int | get_port (void) const |
returns tcp port number that the server listens for connections on More... | |
void | set_port (unsigned int p) |
sets tcp port number that the server listens for connections on More... | |
boost::asio::ip::address | get_address (void) const |
returns IP address that the server listens for connections on More... | |
void | set_address (const boost::asio::ip::address &addr) |
sets IP address that the server listens for connections on More... | |
const boost::asio::ip::tcp::endpoint & | get_endpoint (void) const |
returns tcp endpoint that the server listens for connections on More... | |
void | set_endpoint (const boost::asio::ip::tcp::endpoint &ep) |
sets tcp endpoint that the server listens for connections on More... | |
bool | get_ssl_flag (void) const |
returns true if the server uses SSL to encrypt connections More... | |
void | set_ssl_flag (bool b=true) |
sets value of SSL flag (true if the server uses SSL to encrypt connections) More... | |
connection::ssl_context_type & | get_ssl_context_type (void) |
returns the SSL context for configuration More... | |
bool | is_listening (void) const |
returns true if the server is listening for connections More... | |
void | set_logger (logger log_ptr) |
sets the logger to be used More... | |
logger | get_logger (void) |
returns the logger currently in use More... | |
boost::asio::ip::tcp::acceptor & | get_acceptor (void) |
returns mutable reference to the TCP connection acceptor More... | |
const boost::asio::ip::tcp::acceptor & | get_acceptor (void) const |
returns const reference to the TCP connection acceptor More... | |
Static Public Member Functions | |
static std::string | strip_trailing_slash (const std::string &str) |
static void | handle_bad_request (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn) |
static void | handle_not_found_request (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn) |
static void | handle_server_error (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn, const std::string &error_msg) |
static void | handle_forbidden_request (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn, const std::string &error_msg) |
static void | handle_method_not_allowed (const http::request_ptr &http_request_ptr, const tcp::connection_ptr &tcp_conn, const std::string &allowed_methods="") |
Protected Member Functions | |
virtual void | handle_connection (const tcp::connection_ptr &tcp_conn) |
virtual void | handle_request (const http::request_ptr &http_request_ptr, const 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 |
Protected Member Functions inherited from pion::tcp::server | |
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 More... | |
virtual void | after_stopping (void) |
called after the TCP server has stopped listing for new connections More... | |
boost::asio::io_service & | get_io_service (void) |
returns an async I/O service used to schedule work More... | |
Additional Inherited Members | |
Protected Attributes inherited from pion::tcp::server | |
logger | m_logger |
primary logging interface used by this class More... | |
server: a server that handles HTTP connections
typedef boost::function3<void, const http::request_ptr&, const tcp::connection_ptr&, const std::string&> pion::http::server::error_handler_t |
handler for requests that result in "500 Server Error"
typedef boost::function2<void, const http::request_ptr&, const tcp::connection_ptr&> pion::http::server::request_handler_t |
type of function that is used to handle requests
|
inlinevirtual |
default destructor
Reimplemented from pion::tcp::server.
|
inlineexplicit |
creates a new server object
tcp_port | port number used to listen for new connections (IPv4) |
References PION_GET_LOGGER.
|
inlineexplicit |
creates a new server object
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
References PION_GET_LOGGER.
|
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) |
References PION_GET_LOGGER.
|
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) |
References PION_GET_LOGGER.
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 |
References pion::tcp::server::m_logger, PION_LOG_INFO, 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 |
References pion::tcp::server::m_logger, PION_LOG_INFO, and strip_trailing_slash().
Referenced by pion::http::plugin_server::add_service(), and pion::http::plugin_server::load_service().
|
inlinevirtual |
clears the collection of resources recognized by the HTTP server
Reimplemented in pion::http::plugin_server.
Referenced by pion::http::plugin_server::clear().
|
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 |
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 |
References pion::http::response_writer::create(), pion::tcp::connection::finish(), pion::http::types::RESPONSE_CODE_BAD_REQUEST, and pion::http::types::RESPONSE_MESSAGE_BAD_REQUEST.
|
protectedvirtual |
handles a new TCP connection
tcp_conn | the new TCP connection to handle |
Reimplemented from pion::tcp::server.
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 |
References pion::http::response_writer::create(), pion::tcp::connection::finish(), pion::http::types::RESPONSE_CODE_FORBIDDEN, pion::http::types::RESPONSE_MESSAGE_FORBIDDEN, 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 |
References pion::http::response_writer::create(), pion::tcp::connection::finish(), pion::http::types::RESPONSE_CODE_METHOD_NOT_ALLOWED, pion::http::types::RESPONSE_MESSAGE_METHOD_NOT_ALLOWED, 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 |
References pion::http::response_writer::create(), pion::tcp::connection::finish(), pion::http::types::RESPONSE_CODE_NOT_FOUND, pion::http::types::RESPONSE_MESSAGE_NOT_FOUND, 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 |
References pion::diagnostic_information(), find_request_handler(), pion::http::parser::get_error_category(), pion::tcp::server::get_port(), pion::tcp::connection::LIFECYCLE_CLOSE, pion::tcp::server::m_logger, PION_LOG_DEBUG, PION_LOG_ERROR, PION_LOG_INFO, 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 |
References pion::http::response_writer::create(), pion::tcp::connection::finish(), pion::http::types::RESPONSE_CODE_SERVER_ERROR, pion::http::types::RESPONSE_MESSAGE_SERVER_ERROR, 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 |
References pion::tcp::server::m_logger, PION_LOG_INFO, and strip_trailing_slash().
|
inline |
sets the handler object for authentication verification processing
Referenced by pion::http::plugin_server::load_service_config().
|
inline |
sets the function that handles bad HTTP requests
|
inline |
sets the function that handles requests which match no other web services
|
inline |
sets the maximum length for HTTP request payload content
|
inline |
sets the function that handles requests which match no other web services
|
inlinestatic |
strips trailing slash from a string, if one exists
str | the original string |
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().