Request handling class More...
#include <request.hpp>
Classes | |
class | Messages |
Queue type for pending messages. More... | |
Public Member Functions | |
Request () | |
Initializes what it can. set() must be called by Manager before the data is usable. | |
Protected Member Functions | |
const Http::Environment< charT > & | environment () const |
Accessor for the data structure containing all HTTP environment data. | |
virtual bool | response ()=0 |
Response generator. | |
virtual void | inHandler (int bytesReceived) |
Generate a data input response. | |
virtual void | errorHandler (const std::exception &error) |
Called when an exception is caught. | |
const Message & | message () const |
The message associated with the current handler() call. | |
void | setloc (std::locale loc_) |
Set the requests locale. | |
const boost::function< void(Message)> & | callback () const |
Accessor for the callback function for dealings outside the fastcgi++ library. | |
Protocol::Role | role () const |
See the requests role. | |
Protected Attributes | |
Fcgistream< charT, std::char_traits< charT > > | out |
Standard output stream to the client. | |
Fcgistream< charT, std::char_traits< charT > > | err |
Output stream to the HTTP server error log. | |
std::locale | loc |
The locale associated with the request. Should be set with setloc(), not directly. | |
Private Member Functions | |
bool | handler () |
Request Handler. | |
void | complete () |
Generates an END_REQUEST FastCGI record. | |
void | set (Protocol::FullId id_, Transceiver &transceiver_, Protocol::Role role_, bool killCon_, boost::function< void(Message)> callback_) |
Set's up the request with the data it needs. | |
Private Attributes | |
Message | m_message |
The message associated with the current handler() call. | |
boost::function< void(Message)> | m_callback |
The callback function for dealings outside the fastcgi++ library. | |
Http::Environment< charT > | m_environment |
The data structure containing all HTTP environment data. | |
Messages | messages |
A queue of messages to be handler by the request. | |
Transceiver * | transceiver |
Pointer to the transceiver object that will send data to the other side. | |
Protocol::Role | m_role |
The role that the other side expects this request to play. | |
Protocol::FullId | id |
The complete ID (request id & file descriptor) associated with the request. | |
bool | killCon |
Boolean value indicating whether or not the file descriptor should be closed upon completion. | |
Protocol::RecordType | state |
What the request is current doing. | |
Friends | |
class | Manager |
Request handling class
Derivations of this class will handle requests. This includes building the environment data, processing post/get data, fetching data (files, database), and producing a response. Once all client data is organized, response() will be called. At minimum, derivations of this class must define response().
If you want to use UTF-8 encoding pass wchar_t as the template argument, use setloc() to setup a UTF-8 locale and use wide character unicode internally for everything. If you want to use a 8bit character set encoding pass char as the template argument and setloc() a locale with the corresponding character set.
charT | Character type for internal processing (wchar_t or char) |
Definition at line 59 of file request.hpp.
Fastcgipp::Request< charT >::Request | ( | ) | [inline] |
Initializes what it can. set() must be called by Manager before the data is usable.
Definition at line 63 of file request.hpp.
References Fastcgipp::Request< charT >::m_environment, Fastcgipp::Request< charT >::out, and Fastcgipp::Request< charT >::setloc().
const boost::function<void(Message)>& Fastcgipp::Request< charT >::callback | ( | ) | const [inline, protected] |
Accessor for the callback function for dealings outside the fastcgi++ library.
The purpose of the callback object is to provide a thread safe mechanism for functions and classes outside the fastcgi++ library to talk to the requests. Should the library wish to have another thread process or fetch some data, that thread can call this function when it is finished. It is equivalent to this:
void callback(Message msg);
The sole parameter is a Message that contains both a type value for processing by response() and the raw castable data.
Definition at line 154 of file request.hpp.
References Fastcgipp::Request< charT >::m_callback.
void Fastcgipp::Request< charT >::complete | ( | ) | [private] |
Generates an END_REQUEST FastCGI record.
Definition at line 141 of file request.cpp.
References Fastcgipp::Fcgistream< charT, traits >::Fcgibuf::buffer, Fastcgipp::Protocol::END_REQUEST, Fastcgipp::Protocol::REQUEST_COMPLETE, Fastcgipp::Transceiver::requestWrite(), Fastcgipp::Transceiver::secureWrite(), Fastcgipp::Fcgistream< charT, traits >::Fcgibuf::transceiver, and Fastcgipp::Protocol::version.
const Http::Environment<charT>& Fastcgipp::Request< charT >::environment | ( | ) | const [inline, protected] |
Accessor for the data structure containing all HTTP environment data.
Definition at line 67 of file request.hpp.
References Fastcgipp::Request< charT >::m_environment.
void Fastcgipp::Request< charT >::errorHandler | ( | const std::exception & | error ) | [protected, virtual] |
Called when an exception is caught.
This function is called whenever an exception is caught inside the request. By default it will output some data to the error log and send a standard 500 Internal Server Error message to the user. Override for more specialized purposes.
[in] | error | Exception caught |
Definition at line 295 of file request.cpp.
bool Fastcgipp::Request< charT >::handler | ( | ) | [private] |
Request Handler.
This function is called by Manager::handler() to handle messages destined for the request. It deals with FastCGI messages (type=0) while passing all other messages off to response().
Definition at line 179 of file request.cpp.
References Fastcgipp::Protocol::ABORT_REQUEST, Fastcgipp::Protocol::AUTHORIZER, Fastcgipp::Fcgistream< charT, traits >::Fcgibuf::buffer, Fastcgipp::Protocol::END_REQUEST, Fastcgipp::Protocol::IN, Fastcgipp::Protocol::OUT, Fastcgipp::Protocol::PARAMS, Fastcgipp::Transceiver::requestWrite(), Fastcgipp::Protocol::RESPONDER, Fastcgipp::Transceiver::secureWrite(), Fastcgipp::Fcgistream< charT, traits >::Fcgibuf::transceiver, Fastcgipp::Fcgistream< charT, traits >::Fcgibuf::type, Fastcgipp::Protocol::UNKNOWN_ROLE, and Fastcgipp::Protocol::version.
virtual void Fastcgipp::Request< charT >::inHandler | ( | int | bytesReceived ) | [inline, protected, virtual] |
Generate a data input response.
This function exists should the library user wish to do something like generate a partial response based on bytes received from the client. The function is called by handler() every time a FastCGI IN record is received. The function has no access to the data, but knows exactly how much was received based on the value that was passed. Note this value represents the amount of data received in the individual record, not the total amount received in the environment. If the library user wishes to have such a value they would have to keep a tally of all size values passed.
[in] | bytesReceived | Amount of bytes received in this FastCGI record |
Definition at line 106 of file request.hpp.
const Message& Fastcgipp::Request< charT >::message | ( | ) | const [inline, protected] |
The message associated with the current handler() call.
This is only of use to the library user when a non FastCGI (type=0) Message is passed by using the requests callback.
Definition at line 128 of file request.hpp.
References Fastcgipp::Request< charT >::m_message.
virtual bool Fastcgipp::Request< charT >::response | ( | ) | [protected, pure virtual] |
Response generator.
This function is called by handler() once all request data has been received from the other side or if a Message not of a FastCGI type has been passed to it. The function shall return true if it has completed the response and false if it has not (waiting for a callback message to be sent).
Protocol::Role Fastcgipp::Request< charT >::role | ( | ) | const [inline, protected] |
See the requests role.
Definition at line 157 of file request.hpp.
References Fastcgipp::Request< charT >::m_role.
void Fastcgipp::Request< charT >::set | ( | Protocol::FullId | id_, |
Transceiver & | transceiver_, | ||
Protocol::Role | role_, | ||
bool | killCon_, | ||
boost::function< void(Message)> | callback_ | ||
) | [inline, private] |
Set's up the request with the data it needs.
This function is an "after-the-fact" constructor that build vital initial data for the request.
[in] | id_ | Complete ID of the request |
[in] | transceiver_ | Transceiver object the request will use |
[in] | role_ | The role that the other side expects this request to play |
[in] | killCon_ | Boolean value indicating whether or not the file descriptor should be closed upon completion |
[in] | callback_ | Callback function capable of passing messages to the request |
Definition at line 227 of file request.hpp.
References Fastcgipp::Protocol::ERR, Fastcgipp::Request< charT >::err, Fastcgipp::Request< charT >::killCon, Fastcgipp::Request< charT >::m_callback, Fastcgipp::Request< charT >::m_role, Fastcgipp::Protocol::OUT, Fastcgipp::Request< charT >::out, Fastcgipp::Fcgistream< charT, traits >::set(), and Fastcgipp::Request< charT >::transceiver.
void Fastcgipp::Request< charT >::setloc | ( | std::locale | loc_ ) | [protected] |
Set the requests locale.
This function both sets loc to the locale passed to it and imbues the locale into the out and err stream. The user should always call this function as opposed to setting the locales directly is this functions insures the utf8 code conversion is functioning properly.
[in] | loc_ | New locale |
Definition at line 286 of file request.cpp.
Referenced by Fastcgipp::Request< charT >::Request().
friend class Manager [friend] |
Definition at line 204 of file request.hpp.
Fcgistream<charT, std::char_traits<charT> > Fastcgipp::Request< charT >::err [protected] |
Output stream to the HTTP server error log.
To dump data directly through the stream without it being code converted and bypassing the stream buffer call Fcgistream::dump()
Definition at line 82 of file request.hpp.
Referenced by Fastcgipp::Request< charT >::set().
Protocol::FullId Fastcgipp::Request< charT >::id [private] |
The complete ID (request id & file descriptor) associated with the request.
Definition at line 210 of file request.hpp.
bool Fastcgipp::Request< charT >::killCon [private] |
Boolean value indicating whether or not the file descriptor should be closed upon completion.
Definition at line 212 of file request.hpp.
Referenced by Fastcgipp::Request< charT >::set().
std::locale Fastcgipp::Request< charT >::loc [protected] |
The locale associated with the request. Should be set with setloc(), not directly.
Definition at line 119 of file request.hpp.
boost::function<void(Message)> Fastcgipp::Request< charT >::m_callback [private] |
The callback function for dealings outside the fastcgi++ library.
The purpose of the callback object is to provide a thread safe mechanism for functions and classes outside the fastcgi++ library to talk to the requests. Should the library wish to have another thread process or fetch some data, that thread can call this function when it is finished. It is equivalent to this:
void callback(Message msg);
The sole parameter is a Message that contains both a type value for processing by response() and the raw castable data.
Definition at line 181 of file request.hpp.
Referenced by Fastcgipp::Request< charT >::callback(), and Fastcgipp::Request< charT >::set().
Http::Environment<charT> Fastcgipp::Request< charT >::m_environment [private] |
The data structure containing all HTTP environment data.
Definition at line 184 of file request.hpp.
Referenced by Fastcgipp::Request< charT >::environment(), and Fastcgipp::Request< charT >::Request().
Message Fastcgipp::Request< charT >::m_message [private] |
The message associated with the current handler() call.
This is only of use to the library user when a non FastCGI (type=0) Message is passed by using the requests callback.
Definition at line 167 of file request.hpp.
Referenced by Fastcgipp::Request< charT >::message().
Protocol::Role Fastcgipp::Request< charT >::m_role [private] |
The role that the other side expects this request to play.
Definition at line 208 of file request.hpp.
Referenced by Fastcgipp::Request< charT >::role(), and Fastcgipp::Request< charT >::set().
Messages Fastcgipp::Request< charT >::messages [private] |
A queue of messages to be handler by the request.
Definition at line 193 of file request.hpp.
Fcgistream<charT, std::char_traits<charT> > Fastcgipp::Request< charT >::out [protected] |
Standard output stream to the client.
To dump data directly through the stream without it being code converted and bypassing the stream buffer call Fcgistream::dump()
Definition at line 76 of file request.hpp.
Referenced by Fastcgipp::Request< charT >::Request(), and Fastcgipp::Request< charT >::set().
Protocol::RecordType Fastcgipp::Request< charT >::state [private] |
What the request is current doing.
Definition at line 214 of file request.hpp.
Transceiver* Fastcgipp::Request< charT >::transceiver [private] |
Pointer to the transceiver object that will send data to the other side.
Definition at line 206 of file request.hpp.
Referenced by Fastcgipp::Request< charT >::set().