pion::http::server Class Reference

#include <server.hpp>

Inherits pion::tcp::server.

Inherited by pion::http::plugin_server.

List of all members.

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

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

Detailed Description

server: a server that handles HTTP connections

Definition at line 36 of file server.hpp.


Constructor & Destructor Documentation

pion::http::server::server ( const unsigned int  tcp_port = 0  )  [inline, explicit]

creates a new server object

Parameters:
tcp_port port number used to listen for new connections (IPv4)

Reimplemented from pion::tcp::server.

Definition at line 58 of file server.hpp.

pion::http::server::server ( const boost::asio::ip::tcp::endpoint &  endpoint  )  [inline, explicit]

creates a new server object

Parameters:
endpoint TCP endpoint used to listen for new connections (see ASIO docs)

Reimplemented from pion::tcp::server.

Definition at line 73 of file server.hpp.

pion::http::server::server ( scheduler sched,
const unsigned int  tcp_port = 0 
) [inline, explicit]

creates a new server object

Parameters:
sched the scheduler that will be used to manage worker threads
tcp_port port number used to listen for new connections (IPv4)

Reimplemented from pion::tcp::server.

Definition at line 89 of file server.hpp.

pion::http::server::server ( scheduler sched,
const boost::asio::ip::tcp::endpoint &  endpoint 
) [inline]

creates a new server object

Parameters:
sched the scheduler that will be used to manage worker threads
endpoint TCP endpoint used to listen for new connections (see ASIO docs)

Reimplemented from pion::tcp::server.

Definition at line 105 of file server.hpp.


Member Function Documentation

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

Parameters:
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

Parameters:
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().

bool pion::http::server::find_request_handler ( const std::string &  resource,
request_handler_t request_handler 
) const [protected, virtual]

searches for the appropriate request handler to use for a given resource

Parameters:
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().

void pion::http::server::handle_bad_request ( http::request_ptr &  http_request_ptr,
tcp::connection_ptr &  tcp_conn 
) [static]

used to send responses when a bad HTTP request is made

Parameters:
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().

void pion::http::server::handle_connection ( tcp::connection_ptr &  tcp_conn  )  [protected, virtual]

handles a new TCP connection

Parameters:
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().

void pion::http::server::handle_forbidden_request ( http::request_ptr &  http_request_ptr,
tcp::connection_ptr &  tcp_conn,
const std::string &  error_msg 
) [static]

used to send responses when a request is forbidden

Parameters:
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().

void pion::http::server::handle_method_not_allowed ( http::request_ptr &  http_request_ptr,
tcp::connection_ptr &  tcp_conn,
const std::string &  allowed_methods = "" 
) [static]

used to send responses when a method is not allowed

Parameters:
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().

void pion::http::server::handle_not_found_request ( http::request_ptr &  http_request_ptr,
tcp::connection_ptr &  tcp_conn 
) [static]

used to send responses when no web services can handle the request

Parameters:
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().

void pion::http::server::handle_request ( http::request_ptr &  http_request_ptr,
tcp::connection_ptr &  tcp_conn,
const boost::system::error_code &  ec 
) [protected, virtual]

handles a new HTTP request

Parameters:
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().

void pion::http::server::handle_server_error ( http::request_ptr &  http_request_ptr,
tcp::connection_ptr &  tcp_conn,
const std::string &  error_msg 
) [static]

used to send responses when a server error occurs

Parameters:
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

Parameters:
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().

void pion::http::server::set_authentication ( http::auth_ptr  auth  )  [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().

static std::string pion::http::server::strip_trailing_slash ( const std::string &  str  )  [inline, static]

The documentation for this class was generated from the following files:

Generated on 16 Sep 2013 for pion by  doxygen 1.6.1