Kea 2.7.5
|
Represents a single exchange of the HTTP messages. More...
#include <connection.h>
Public Member Functions | |
Transaction (const HttpResponseCreatorPtr &response_creator, const HttpRequestPtr &request=HttpRequestPtr()) | |
Constructor. | |
void | consumeOutputBuf (const size_t length) |
Erases n bytes from the beginning of the output buffer. | |
char * | getInputBufData () |
Returns pointer to the first byte of the input buffer. | |
size_t | getInputBufSize () const |
Returns input buffer size. | |
const char * | getOutputBufData () const |
Returns pointer to the first byte of the output buffer. | |
size_t | getOutputBufSize () const |
Returns size of the output buffer. | |
HttpRequestParserPtr | getParser () const |
Returns parser instance associated with the transaction. | |
HttpRequestPtr | getRequest () const |
Returns request instance associated with the transaction. | |
bool | outputDataAvail () const |
Checks if the output buffer contains some data to be sent. | |
void | setOutputBuf (const std::string &response) |
Replaces output buffer contents with new contents. | |
Static Public Member Functions | |
static TransactionPtr | create (const HttpResponseCreatorPtr &response_creator) |
Creates new transaction instance. | |
static TransactionPtr | spawn (const HttpResponseCreatorPtr &response_creator, const TransactionPtr &transaction) |
Creates new transaction from the current transaction. | |
Represents a single exchange of the HTTP messages.
In HTTP/1.1 multiple HTTP message exchanges may be conducted over the same persistent connection before the connection is closed. Since ASIO handlers for these exchanges may be sometimes executed out of order, there is a need to associate the states of the exchanges with the appropriate ASIO handlers. This object represents such state and includes: received request, request parser (being in the particular state of parsing), input buffer and the output buffer.
The new Transaction
instance is created when the connection is established and the server starts receiving the HTTP request. The shared pointer to the created transaction is passed between the asynchronous handlers. Therefore, as long as the asynchronous communication is conducted the instance of the transaction is held by the IO service which runs the handlers. The transaction instance exists as long as the asynchronous handlers for the given request/response exchange are executed. When the server responds to the client and all corresponding IO handlers are invoked the transaction is automatically destroyed.
The timeout may occur anytime during the transaction. In such cases, a new transaction instance is created to send the HTTP 408 (timeout) response to the client. Creation of the new transaction for the timeout response is necessary because there may be some asynchronous handlers scheduled by the original transaction which rely on the original transaction's state. The timeout response's state is held within the new transaction spawned from the original transaction.
Definition at line 119 of file connection.h.
isc::http::HttpConnection::Transaction::Transaction | ( | const HttpResponseCreatorPtr & | response_creator, |
const HttpRequestPtr & | request = HttpRequestPtr() ) |
Constructor.
response_creator | Pointer to the response creator being used for generating a response from the request. |
request | Pointer to the HTTP request. If the request is null, the constructor creates new request instance using the provided response creator. |
Definition at line 35 of file connection.cc.
|
inline |
Erases n bytes from the beginning of the output buffer.
length | Number of bytes to be erased. |
Definition at line 210 of file connection.h.
|
static |
Creates new transaction instance.
It is called when the HTTP server has just scheduled asynchronous reading of the HTTP message.
response_creator | Pointer to the response creator to be passed to the transaction's constructor. |
Definition at line 45 of file connection.cc.
Referenced by isc::http::HttpConnection::doRead().
|
inline |
Returns pointer to the first byte of the input buffer.
Definition at line 172 of file connection.h.
|
inline |
Returns input buffer size.
Definition at line 177 of file connection.h.
|
inline |
Returns pointer to the first byte of the output buffer.
Definition at line 191 of file connection.h.
|
inline |
Returns size of the output buffer.
Definition at line 196 of file connection.h.
|
inline |
Returns parser instance associated with the transaction.
Definition at line 167 of file connection.h.
|
inline |
Returns request instance associated with the transaction.
Definition at line 162 of file connection.h.
|
inline |
Checks if the output buffer contains some data to be sent.
Definition at line 186 of file connection.h.
|
inline |
Replaces output buffer contents with new contents.
response | New contents for the output buffer. |
Definition at line 203 of file connection.h.
|
static |
Creates new transaction from the current transaction.
This method creates new transaction and inherits the request from the existing transaction. This is used when the timeout occurs during the messages exchange. The server creates the new transaction to handle the timeout but this new transaction must include the request instance so as HTTP version information can be inferred from it while sending the timeout response. The HTTP version information should match between the request and the response.
response_creator | Pointer to the response creator. |
transaction | Existing transaction from which the request should be inherited. If the transaction is null, the new (dummy) request is created for the new transaction. |
Definition at line 50 of file connection.cc.
Referenced by isc::http::HttpConnection::requestTimeoutCallback().