ゴミ箱
Public Member Functions | List of all members
HttpListener Class Reference

Public Member Functions

 HttpListener ()=delete
 
 HttpListener (tcp::acceptor &acceptor, Router &router)
 
void accept ()
 
void send_response ()
 
void prepare_response ()
 
template<typename Error >
void send_error_response (Error &&error, http::status status=http::status::internal_server_error)
 
void read_request ()
 
void handle_request ()
 

Detailed Description

HTTP boost::io_service handler.

Object of this class should live as long as boost::io_service::run() is executing. It can be achieved through different means:

First can case can be found in multiple examples. But the second works as charm even in multithreaded environment. So why settle for unnecessary overhead of shared_ptr?

TODO: There is a question whether you'd need a synchronization for pure heap-allocated members.

Constructor & Destructor Documentation

HttpListener::HttpListener ( )
delete
HttpListener::HttpListener ( tcp::acceptor &  acceptor,
Router router 
)
inline

Member Function Documentation

void HttpListener::accept ( )
inline

Handle new incoming connection.

After finishing handling each new connection the function is called once again. The function should be called only after request's handling is finished! As long as it is called there will be jobs to do for boost::io_service and it will loop through them forever.

void HttpListener::handle_request ( )
inline

Handles HTTP Request.

TODO: Next step is to think of API to provide routing.

void HttpListener::prepare_response ( )
inline

Finalize response by setting default headers.

void HttpListener::read_request ( )
inline

Reads Client's request

On failure to read it would make sense to send back some meaningful error response.

template<typename Error >
void HttpListener::send_error_response ( Error &&  error,
http::status  status = http::status::internal_server_error 
)
inline

Sends response with error to client.

Parameters
[in]errorError type. It is inserted into response using stream operator.
[in]statusHTTP Status code. Default is 500.
void HttpListener::send_response ( )
inline

Sends response back to client.

Closes socket and accepts another connection.


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