pion-net
4.0.9
|
#include <HTTPServer.hpp>
Inherits pion::net::TCPServer.
Inherited by pion::net::WebServer.
Public Types | |
typedef boost::function2< void, HTTPRequestPtr &, TCPConnectionPtr & > | RequestHandler |
type of function that is used to handle requests | |
typedef boost::function3< void, HTTPRequestPtr &, TCPConnectionPtr &, const std::string & > | ServerErrorHandler |
handler for requests that result in "500 Server Error" |
Public Member Functions | |
virtual | ~HTTPServer () |
default destructor | |
HTTPServer (const unsigned int tcp_port=0) | |
HTTPServer (const boost::asio::ip::tcp::endpoint &endpoint) | |
HTTPServer (PionScheduler &scheduler, const unsigned int tcp_port=0) | |
HTTPServer (PionScheduler &scheduler, const boost::asio::ip::tcp::endpoint &endpoint) | |
void | addResource (const std::string &resource, RequestHandler request_handler) |
void | removeResource (const std::string &resource) |
void | addRedirect (const std::string &requested_resource, const std::string &new_resource) |
void | setBadRequestHandler (RequestHandler h) |
sets the function that handles bad HTTP requests | |
void | setNotFoundHandler (RequestHandler h) |
sets the function that handles requests which match no other web services | |
void | setServerErrorHandler (ServerErrorHandler 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 | setAuthentication (HTTPAuthPtr auth) |
void | setMaxContentLength (std::size_t n) |
sets the maximum length for HTTP request payload content | |
![]() | |
virtual | ~TCPServer () |
default destructor | |
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 | setSSLKeyFile (const std::string &pem_key_file) |
std::size_t | getConnections (void) const |
returns the number of active tcp connections | |
unsigned int | getPort (void) const |
returns tcp port number that the server listens for connections on | |
void | setPort (unsigned int p) |
sets tcp port number that the server listens for connections on | |
boost::asio::ip::address | getAddress (void) const |
returns IP address that the server listens for connections on | |
void | setAddress (const boost::asio::ip::address &addr) |
sets IP address that the server listens for connections on | |
const boost::asio::ip::tcp::endpoint & | getEndpoint (void) const |
returns tcp endpoint that the server listens for connections on | |
void | setEndpoint (const boost::asio::ip::tcp::endpoint &ep) |
sets tcp endpoint that the server listens for connections on | |
bool | getSSLFlag (void) const |
returns true if the server uses SSL to encrypt connections | |
void | setSSLFlag (bool b=true) |
sets value of SSL flag (true if the server uses SSL to encrypt connections) | |
TCPConnection::SSLContext & | getSSLContext (void) |
returns the SSL context for configuration | |
bool | isListening (void) const |
returns true if the server is listening for connections | |
void | setLogger (PionLogger log_ptr) |
sets the logger to be used | |
PionLogger | getLogger (void) |
returns the logger currently in use |
Static Public Member Functions | |
static std::string | stripTrailingSlash (const std::string &str) |
static void | handleBadRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn) |
static void | handleNotFoundRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn) |
static void | handleServerError (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const std::string &error_msg) |
static void | handleForbiddenRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const std::string &error_msg) |
static void | handleMethodNotAllowed (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const std::string &allowed_methods="") |
Protected Member Functions | |
virtual void | handleConnection (TCPConnectionPtr &tcp_conn) |
virtual void | handleRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn, const boost::system::error_code &ec) |
virtual bool | findRequestHandler (const std::string &resource, RequestHandler &request_handler) const |
![]() | |
TCPServer (const unsigned int tcp_port) | |
TCPServer (const boost::asio::ip::tcp::endpoint &endpoint) | |
TCPServer (PionScheduler &scheduler, const unsigned int tcp_port=0) | |
TCPServer (PionScheduler &scheduler, const boost::asio::ip::tcp::endpoint &endpoint) | |
virtual void | beforeStarting (void) |
called before the TCP server starts listening for new connections | |
virtual void | afterStopping (void) |
called after the TCP server has stopped listing for new connections | |
boost::asio::io_service & | getIOService (void) |
returns an async I/O service used to schedule work |
Additional Inherited Members | |
![]() | |
PionLogger | m_logger |
primary logging interface used by this class |
HTTPServer: a server that handles HTTP connections
Definition at line 35 of file HTTPServer.hpp.
|
inlineexplicit |
creates a new HTTPServer object
tcp_port | port number used to listen for new connections (IPv4) |
Definition at line 57 of file HTTPServer.hpp.
|
inlineexplicit |
creates a new HTTPServer object
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
Definition at line 72 of file HTTPServer.hpp.
|
inlineexplicit |
creates a new HTTPServer object
scheduler | the PionScheduler that will be used to manage worker threads |
tcp_port | port number used to listen for new connections (IPv4) |
Definition at line 88 of file HTTPServer.hpp.
|
inline |
creates a new HTTPServer object
scheduler | the PionScheduler that will be used to manage worker threads |
endpoint | TCP endpoint used to listen for new connections (see ASIO docs) |
Definition at line 104 of file HTTPServer.hpp.
void pion::net::HTTPServer::addRedirect | ( | 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 162 of file HTTPServer.cpp.
References pion::net::TCPServer::m_logger, and stripTrailingSlash().
void pion::net::HTTPServer::addResource | ( | const std::string & | resource, |
RequestHandler | 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 145 of file HTTPServer.cpp.
References pion::net::TCPServer::m_logger, and stripTrailingSlash().
Referenced by pion::net::WebServer::addService(), and pion::net::WebServer::loadService().
|
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 119 of file HTTPServer.cpp.
Referenced by handleRequest().
|
static |
used to send responses when a bad HTTP request is made
http_request | the new HTTP request to handle |
tcp_conn | the TCP connection that has the new request |
Definition at line 172 of file HTTPServer.cpp.
References pion::net::HTTPResponseWriter::create(), and pion::net::TCPConnection::finish().
|
protectedvirtual |
handles a new TCP connection
tcp_conn | the new TCP connection to handle |
Reimplemented from pion::net::TCPServer.
Definition at line 27 of file HTTPServer.cpp.
References pion::net::HTTPRequestReader::create(), and handleRequest().
|
static |
used to send responses when a request is forbidden
http_request | 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 235 of file HTTPServer.cpp.
References pion::net::HTTPResponseWriter::create(), and pion::net::TCPConnection::finish().
|
static |
used to send responses when a method is not allowed
http_request | 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 262 of file HTTPServer.cpp.
References pion::net::HTTPResponseWriter::create(), and pion::net::TCPConnection::finish().
|
static |
used to send responses when no web services can handle the request
http_request | the new HTTP request to handle |
tcp_conn | the TCP connection that has the new request |
Definition at line 190 of file HTTPServer.cpp.
References pion::net::HTTPResponseWriter::create(), and pion::net::TCPConnection::finish().
|
protectedvirtual |
handles a new HTTP request
http_request | 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 36 of file HTTPServer.cpp.
References findRequestHandler(), pion::net::HTTPParser::getErrorCategory(), pion::net::TCPServer::getPort(), pion::net::TCPServer::m_logger, and stripTrailingSlash().
Referenced by handleConnection().
|
static |
used to send responses when a server error occurs
http_request | 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 212 of file HTTPServer.cpp.
References pion::net::HTTPResponseWriter::create(), and pion::net::TCPConnection::finish().
void pion::net::HTTPServer::removeResource | ( | const std::string & | resource | ) |
removes a web service from the HTTP server
resource | the resource name or uri-stem to remove |
Definition at line 154 of file HTTPServer.cpp.
References pion::net::TCPServer::m_logger, and stripTrailingSlash().
|
inline |
sets the handler object for authentication verification processing
Definition at line 220 of file HTTPServer.hpp.
Referenced by pion::net::WebServer::loadServiceConfig().
|
inlinestatic |
strips trailing slash from a string, if one exists
str | the original string |
Definition at line 159 of file HTTPServer.hpp.
Referenced by pion::net::HTTPAuth::addPermit(), addRedirect(), addResource(), pion::net::HTTPAuth::addRestrict(), pion::net::WebServer::addService(), handleRequest(), pion::net::WebServer::loadService(), pion::net::HTTPAuth::needAuthentication(), pion::net::HTTPCookieAuth::processLogin(), removeResource(), and pion::net::WebServer::setServiceOption().