Kea  2.3.5-git
isc::http::HttpConnection::Transaction Class Reference

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. More...
 
void consumeOutputBuf (const size_t length)
 Erases n bytes from the beginning of the output buffer. More...
 
char * getInputBufData ()
 Returns pointer to the first byte of the input buffer. More...
 
size_t getInputBufSize () const
 Returns input buffer size. More...
 
const char * getOutputBufData () const
 Returns pointer to the first byte of the output buffer. More...
 
size_t getOutputBufSize () const
 Returns size of the output buffer. More...
 
HttpRequestParserPtr getParser () const
 Returns parser instance associated with the transaction. More...
 
HttpRequestPtr getRequest () const
 Returns request instance associated with the transaction. More...
 
bool outputDataAvail () const
 Checks if the output buffer contains some data to be sent. More...
 
void setOutputBuf (const std::string &response)
 Replaces output buffer contents with new contents. More...
 

Static Public Member Functions

static TransactionPtr create (const HttpResponseCreatorPtr &response_creator)
 Creates new transaction instance. More...
 
static TransactionPtr spawn (const HttpResponseCreatorPtr &response_creator, const TransactionPtr &transaction)
 Creates new transaction from the current transaction. More...
 

Detailed Description

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 118 of file connection.h.

Constructor & Destructor Documentation

◆ Transaction()

isc::http::HttpConnection::Transaction::Transaction ( const HttpResponseCreatorPtr response_creator,
const HttpRequestPtr request = HttpRequestPtr() 
)

Constructor.

Parameters
response_creatorPointer to the response creator being used for generating a response from the request.
requestPointer to the HTTP request. If the request is null, the constructor creates new request instance using the provided response creator.

Definition at line 32 of file connection.cc.

Member Function Documentation

◆ consumeOutputBuf()

void isc::http::HttpConnection::Transaction::consumeOutputBuf ( const size_t  length)
inline

Erases n bytes from the beginning of the output buffer.

Parameters
lengthNumber of bytes to be erased.

Definition at line 209 of file connection.h.

◆ create()

HttpConnection::TransactionPtr isc::http::HttpConnection::Transaction::create ( const HttpResponseCreatorPtr response_creator)
static

Creates new transaction instance.

It is called when the HTTP server has just scheduled asynchronous reading of the HTTP message.

Parameters
response_creatorPointer to the response creator to be passed to the transaction's constructor.
Returns
Pointer to the created transaction instance.

Definition at line 42 of file connection.cc.

Referenced by isc::http::HttpConnection::doRead(), and spawn().

◆ getInputBufData()

char* isc::http::HttpConnection::Transaction::getInputBufData ( )
inline

Returns pointer to the first byte of the input buffer.

Definition at line 171 of file connection.h.

◆ getInputBufSize()

size_t isc::http::HttpConnection::Transaction::getInputBufSize ( ) const
inline

Returns input buffer size.

Definition at line 176 of file connection.h.

◆ getOutputBufData()

const char* isc::http::HttpConnection::Transaction::getOutputBufData ( ) const
inline

Returns pointer to the first byte of the output buffer.

Definition at line 190 of file connection.h.

◆ getOutputBufSize()

size_t isc::http::HttpConnection::Transaction::getOutputBufSize ( ) const
inline

Returns size of the output buffer.

Definition at line 195 of file connection.h.

◆ getParser()

HttpRequestParserPtr isc::http::HttpConnection::Transaction::getParser ( ) const
inline

Returns parser instance associated with the transaction.

Definition at line 166 of file connection.h.

◆ getRequest()

HttpRequestPtr isc::http::HttpConnection::Transaction::getRequest ( ) const
inline

Returns request instance associated with the transaction.

Definition at line 161 of file connection.h.

◆ outputDataAvail()

bool isc::http::HttpConnection::Transaction::outputDataAvail ( ) const
inline

Checks if the output buffer contains some data to be sent.

Returns
true if the output buffer contains data to be sent, false otherwise.

Definition at line 185 of file connection.h.

◆ setOutputBuf()

void isc::http::HttpConnection::Transaction::setOutputBuf ( const std::string &  response)
inline

Replaces output buffer contents with new contents.

Parameters
responseNew contents for the output buffer.

Definition at line 202 of file connection.h.

◆ spawn()

HttpConnection::TransactionPtr isc::http::HttpConnection::Transaction::spawn ( const HttpResponseCreatorPtr response_creator,
const TransactionPtr transaction 
)
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.

Parameters
response_creatorPointer to the response creator.
transactionExisting 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 47 of file connection.cc.

References create().

Referenced by isc::http::HttpConnection::requestTimeoutCallback().

+ Here is the call graph for this function:

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