#include <HTTPServer.hpp>
Inherits pion::net::TCPServer.
Inherited by pion::net::WebServer.
Definition at line 35 of file HTTPServer.hpp.
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 | |
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) |
Protected Member Functions | |
virtual void | handleConnection (TCPConnectionPtr &tcp_conn) |
void | handleRequest (HTTPRequestPtr &http_request, TCPConnectionPtr &tcp_conn) |
bool | findRequestHandler (const std::string &resource, RequestHandler &request_handler) const |
pion::net::HTTPServer::HTTPServer | ( | const unsigned int | tcp_port = 0 |
) | [inline, explicit] |
creates a new HTTPServer object
tcp_port | port number used to listen for new connections (IPv4) |
Definition at line 57 of file HTTPServer.hpp.
pion::net::HTTPServer::HTTPServer | ( | const boost::asio::ip::tcp::endpoint & | endpoint | ) | [inline, explicit] |
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.
pion::net::HTTPServer::HTTPServer | ( | PionScheduler & | scheduler, | |
const unsigned int | tcp_port = 0 | |||
) | [inline, explicit] |
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.
pion::net::HTTPServer::HTTPServer | ( | PionScheduler & | scheduler, | |
const boost::asio::ip::tcp::endpoint & | endpoint | |||
) | [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 160 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 143 of file HTTPServer.cpp.
References pion::net::TCPServer::m_logger, and stripTrailingSlash().
Referenced by pion::net::WebServer::addService(), and pion::net::WebServer::loadService().
bool pion::net::HTTPServer::findRequestHandler | ( | const std::string & | resource, | |
RequestHandler & | request_handler | |||
) | const [protected] |
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 117 of file HTTPServer.cpp.
Referenced by handleRequest().
void pion::net::HTTPServer::handleBadRequest | ( | HTTPRequestPtr & | http_request, | |
TCPConnectionPtr & | tcp_conn | |||
) | [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 170 of file HTTPServer.cpp.
References pion::net::HTTPResponseWriter::create(), pion::net::TCPConnection::finish(), pion::net::HTTPTypes::RESPONSE_CODE_BAD_REQUEST, and pion::net::HTTPTypes::RESPONSE_MESSAGE_BAD_REQUEST.
void pion::net::HTTPServer::handleConnection | ( | TCPConnectionPtr & | tcp_conn | ) | [protected, virtual] |
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().
void pion::net::HTTPServer::handleNotFoundRequest | ( | HTTPRequestPtr & | http_request, | |
TCPConnectionPtr & | tcp_conn | |||
) | [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 188 of file HTTPServer.cpp.
References pion::net::HTTPResponseWriter::create(), pion::net::TCPConnection::finish(), pion::net::HTTPTypes::RESPONSE_CODE_NOT_FOUND, and pion::net::HTTPTypes::RESPONSE_MESSAGE_NOT_FOUND.
void pion::net::HTTPServer::handleRequest | ( | HTTPRequestPtr & | http_request, | |
TCPConnectionPtr & | tcp_conn | |||
) | [protected] |
handles a new HTTP request
http_request | the HTTP request to handle | |
tcp_conn | TCP connection containing a new request |
Definition at line 36 of file HTTPServer.cpp.
References findRequestHandler(), pion::net::TCPServer::m_logger, and stripTrailingSlash().
Referenced by handleConnection().
void pion::net::HTTPServer::handleServerError | ( | HTTPRequestPtr & | http_request, | |
TCPConnectionPtr & | tcp_conn, | |||
const std::string & | error_msg | |||
) | [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 210 of file HTTPServer.cpp.
References pion::net::HTTPResponseWriter::create(), pion::net::TCPConnection::finish(), pion::net::HTTPTypes::RESPONSE_CODE_SERVER_ERROR, and pion::net::HTTPTypes::RESPONSE_MESSAGE_SERVER_ERROR.
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 152 of file HTTPServer.cpp.
References pion::net::TCPServer::m_logger, and stripTrailingSlash().
void pion::net::HTTPServer::setAuthentication | ( | HTTPAuthPtr | auth | ) | [inline] |
sets the handler object for authentication verification processing
Definition at line 198 of file HTTPServer.hpp.
Referenced by pion::net::WebServer::loadServiceConfig().
static std::string pion::net::HTTPServer::stripTrailingSlash | ( | const std::string & | str | ) | [inline, static] |
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().