Torc  0.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
TorcHTTPRequest Class Reference

A class to encapsulate an incoming HTTP request. More...

#include <torchttprequest.h>

Public Member Functions

 TorcHTTPRequest (TorcHTTPReader *Reader)
 
void SetConnection (HTTPConnection Connection)
 
void SetStatus (HTTPStatus Status)
 
void SetResponseType (HTTPResponseType Type)
 
void SetResponseContent (const QByteArray &Content)
 
void SetResponseFile (const QString &File)
 
void SetResponseHeader (const QString &Header, const QString &Value)
 
void SetAllowed (int Allowed)
 
void SetAllowGZip (bool Allowed)
 Allow gzip compression for the contents of this request. More...
 
void SetAllowCORS (bool Allowed)
 
void SetCache (int Cache, const QString &Tag=QStringLiteral(""))
 Set the caching behaviour for this response. More...
 
void SetSecure (bool Secure)
 
bool GetSecure (void)
 
HTTPStatus GetHTTPStatus (void) const
 
HTTPType GetHTTPType (void) const
 
HTTPRequestType GetHTTPRequestType (void) const
 
HTTPProtocol GetHTTPProtocol (void) const
 
QString GetUrl (void) const
 
QString GetPath (void) const
 
QString GetMethod (void) const
 
QString GetCache (void) const
 
const QMap< QString, QString > & Headers (void) const
 
const QMap< QString, QString > & Queries (void) const
 
bool GetAllowCORS (void) const
 
void Respond (QTcpSocket *Socket)
 
void Redirected (const QString &Redirected)
 
void Serialise (const QVariant &Data, const QString &Type)
 
bool Unmodified (const QDateTime &LastModified)
 Return true if the resource is unmodified. More...
 
bool Unmodified (void)
 Check whether the resource is equivalent to the last seen version. More...
 
void Authorise (HTTPAuthorisation Authorisation)
 
HTTPAuthorisation IsAuthorised (void) const
 

Static Public Member Functions

static HTTPRequestType RequestTypeFromString (const QString &Type)
 
static QString RequestTypeToString (HTTPRequestType Type)
 
static HTTPProtocol ProtocolFromString (const QString &Protocol)
 
static HTTPStatus StatusFromString (const QString &Status)
 
static QString ProtocolToString (HTTPProtocol Protocol)
 
static QString StatusToString (HTTPStatus Status)
 
static QString ResponseTypeToString (HTTPResponseType Response)
 
static QString AllowedToString (int Allowed)
 
static QString ConnectionToString (HTTPConnection Connection)
 
static int StringToAllowed (const QString &Allowed)
 
static QVector< QPair< quint64, quint64 > > StringToRanges (const QString &Ranges, qint64 Size, qint64 &SizeToSend)
 
static QString RangeToString (QPair< quint64, quint64 > Range, qint64 Size)
 

Static Public Attributes

static char DateFormat [] = "ddd, dd MMM yyyy HH:mm:ss 'UTC'"
 

Protected Member Functions

 ~TorcHTTPRequest ()=default
 
void Initialise (const QString &Method)
 

Protected Attributes

QString m_fullUrl
 
QString m_path
 
QString m_method
 
QString m_query
 
QString m_redirectedTo
 
HTTPType m_type
 
HTTPRequestType m_requestType
 
HTTPProtocol m_protocol
 
HTTPConnection m_connection
 
QVector< QPair< quint64, quint64 > > m_ranges
 
QMap< QString, QString > m_headers
 
QMap< QString, QString > m_queries
 
QByteArray m_content
 
bool m_secure
 
bool m_allowGZip
 
bool m_allowCORS
 
int m_allowed
 
HTTPAuthorisation m_authorised
 
HTTPResponseType m_responseType
 
int m_cache
 
QString m_cacheTag
 
HTTPStatus m_responseStatus
 
QByteArray m_responseContent
 
QString m_responseFile
 
QMap< QString, QString > m_responseHeaders
 

Friends

class TorcWebSocket
 

Detailed Description

A class to encapsulate an incoming HTTP request.

TorcHTTPRequest validates an incoming HTTP request and prepares the appropriate headers for the response.

See also
TorcHTTPServer
TorcHTTPHandler
Todo:

Add support for multiple headers of the same type (e.g. Sec-WebSocket-Protocol).

Support gzip compression for range requests (if it is possible?)

Definition at line 112 of file torchttprequest.h.

Constructor & Destructor Documentation

TorcHTTPRequest::TorcHTTPRequest ( TorcHTTPReader Reader)
explicit

Definition at line 70 of file torchttprequest.cpp.

TorcHTTPRequest::~TorcHTTPRequest ( )
protecteddefault

Member Function Documentation

QString TorcHTTPRequest::AllowedToString ( int  Allowed)
static

Definition at line 875 of file torchttprequest.cpp.

void TorcHTTPRequest::Authorise ( HTTPAuthorisation  Authorisation)

Definition at line 1097 of file torchttprequest.cpp.

QString TorcHTTPRequest::ConnectionToString ( HTTPConnection  Connection)
static

Definition at line 889 of file torchttprequest.cpp.

bool TorcHTTPRequest::GetAllowCORS ( void  ) const

Definition at line 231 of file torchttprequest.cpp.

QString TorcHTTPRequest::GetCache ( void  ) const

Definition at line 296 of file torchttprequest.cpp.

HTTPProtocol TorcHTTPRequest::GetHTTPProtocol ( void  ) const

Definition at line 276 of file torchttprequest.cpp.

HTTPRequestType TorcHTTPRequest::GetHTTPRequestType ( void  ) const

Definition at line 271 of file torchttprequest.cpp.

HTTPStatus TorcHTTPRequest::GetHTTPStatus ( void  ) const

Definition at line 261 of file torchttprequest.cpp.

HTTPType TorcHTTPRequest::GetHTTPType ( void  ) const

Definition at line 266 of file torchttprequest.cpp.

QString TorcHTTPRequest::GetMethod ( void  ) const

Definition at line 291 of file torchttprequest.cpp.

QString TorcHTTPRequest::GetPath ( void  ) const

Definition at line 286 of file torchttprequest.cpp.

bool TorcHTTPRequest::GetSecure ( void  )

Definition at line 256 of file torchttprequest.cpp.

QString TorcHTTPRequest::GetUrl ( void  ) const

Definition at line 281 of file torchttprequest.cpp.

const QMap< QString, QString > & TorcHTTPRequest::Headers ( void  ) const

Definition at line 301 of file torchttprequest.cpp.

void TorcHTTPRequest::Initialise ( const QString &  Method)
protected

Definition at line 108 of file torchttprequest.cpp.

HTTPAuthorisation TorcHTTPRequest::IsAuthorised ( void  ) const

Definition at line 1102 of file torchttprequest.cpp.

HTTPProtocol TorcHTTPRequest::ProtocolFromString ( const QString &  Protocol)
static

Definition at line 780 of file torchttprequest.cpp.

QString TorcHTTPRequest::ProtocolToString ( HTTPProtocol  Protocol)
static

Definition at line 811 of file torchttprequest.cpp.

const QMap< QString, QString > & TorcHTTPRequest::Queries ( void  ) const

Definition at line 306 of file torchttprequest.cpp.

QString TorcHTTPRequest::RangeToString ( QPair< quint64, quint64 >  Range,
qint64  Size 
)
static

Definition at line 1038 of file torchttprequest.cpp.

void TorcHTTPRequest::Redirected ( const QString &  Redirected)

Definition at line 743 of file torchttprequest.cpp.

HTTPRequestType TorcHTTPRequest::RequestTypeFromString ( const QString &  Type)
static

Definition at line 750 of file torchttprequest.cpp.

QString TorcHTTPRequest::RequestTypeToString ( HTTPRequestType  Type)
static

Definition at line 762 of file torchttprequest.cpp.

void TorcHTTPRequest::Respond ( QTcpSocket *  Socket)

Definition at line 311 of file torchttprequest.cpp.

QString TorcHTTPRequest::ResponseTypeToString ( HTTPResponseType  Response)
static

Definition at line 850 of file torchttprequest.cpp.

void TorcHTTPRequest::Serialise ( const QVariant &  Data,
const QString &  Type 
)

Definition at line 1043 of file torchttprequest.cpp.

void TorcHTTPRequest::SetAllowCORS ( bool  Allowed)

Definition at line 226 of file torchttprequest.cpp.

void TorcHTTPRequest::SetAllowed ( int  Allowed)

Definition at line 215 of file torchttprequest.cpp.

void TorcHTTPRequest::SetAllowGZip ( bool  Allowed)

Allow gzip compression for the contents of this request.

Definition at line 221 of file torchttprequest.cpp.

void TorcHTTPRequest::SetCache ( int  Cache,
const QString &  Tag = QStringLiteral("") 
)

Set the caching behaviour for this response.

The default behaviour is to to try and enforce no caching. Standard caching can be enabled with HTTPCacheShortLife or HTTPCacheLongLife with optional use of 'last modified' or ETag for conditional requests. The 'last-modified' and 'ETag' fields are set with the Tag parameter.

Note
If a subclass of TorcHTTPHandler uses the 'last-modified' or 'ETag' headers, it must also be capable of handling the appropriate conditional requests and responding with a '304 Not Modified' as necessary.

Definition at line 245 of file torchttprequest.cpp.

void TorcHTTPRequest::SetConnection ( HTTPConnection  Connection)

Definition at line 183 of file torchttprequest.cpp.

void TorcHTTPRequest::SetResponseContent ( const QByteArray &  Content)

Definition at line 198 of file torchttprequest.cpp.

void TorcHTTPRequest::SetResponseFile ( const QString &  File)

Definition at line 204 of file torchttprequest.cpp.

void TorcHTTPRequest::SetResponseHeader ( const QString &  Header,
const QString &  Value 
)

Definition at line 210 of file torchttprequest.cpp.

void TorcHTTPRequest::SetResponseType ( HTTPResponseType  Type)

Definition at line 193 of file torchttprequest.cpp.

void TorcHTTPRequest::SetSecure ( bool  Secure)

Definition at line 251 of file torchttprequest.cpp.

void TorcHTTPRequest::SetStatus ( HTTPStatus  Status)

Definition at line 188 of file torchttprequest.cpp.

HTTPStatus TorcHTTPRequest::StatusFromString ( const QString &  Status)
static

Definition at line 792 of file torchttprequest.cpp.

QString TorcHTTPRequest::StatusToString ( HTTPStatus  Status)
static

Definition at line 824 of file torchttprequest.cpp.

int TorcHTTPRequest::StringToAllowed ( const QString &  Allowed)
static

Definition at line 901 of file torchttprequest.cpp.

QVector< QPair< quint64, quint64 > > TorcHTTPRequest::StringToRanges ( const QString &  Ranges,
qint64  Size,
qint64 &  SizeToSend 
)
static

Definition at line 916 of file torchttprequest.cpp.

bool TorcHTTPRequest::Unmodified ( const QDateTime &  LastModified)

Return true if the resource is unmodified.

The client must have supplied the 'If-Modified-Since' header and the request must have last-modified caching enabled.

Definition at line 1057 of file torchttprequest.cpp.

bool TorcHTTPRequest::Unmodified ( void  )

Check whether the resource is equivalent to the last seen version.

This method validates the ETag header, which must have been set locally and the client must have sent the 'If-None-Match' header.

Note
ETag's are enclosed in parentheses. This code expects m_cacheTag to already be enclosed (i.e. the incoming ETag is not stripped).

Definition at line 1082 of file torchttprequest.cpp.

Friends And Related Function Documentation

friend class TorcWebSocket
friend

Definition at line 114 of file torchttprequest.h.

Member Data Documentation

char TorcHTTPRequest::DateFormat = "ddd, dd MMM yyyy HH:mm:ss 'UTC'"
static

Definition at line 130 of file torchttprequest.h.

bool TorcHTTPRequest::m_allowCORS
protected

Definition at line 187 of file torchttprequest.h.

int TorcHTTPRequest::m_allowed
protected

Definition at line 188 of file torchttprequest.h.

bool TorcHTTPRequest::m_allowGZip
protected

Definition at line 186 of file torchttprequest.h.

HTTPAuthorisation TorcHTTPRequest::m_authorised
protected

Definition at line 189 of file torchttprequest.h.

int TorcHTTPRequest::m_cache
protected

Definition at line 191 of file torchttprequest.h.

QString TorcHTTPRequest::m_cacheTag
protected

Definition at line 192 of file torchttprequest.h.

HTTPConnection TorcHTTPRequest::m_connection
protected

Definition at line 179 of file torchttprequest.h.

QByteArray TorcHTTPRequest::m_content
protected

Definition at line 183 of file torchttprequest.h.

QString TorcHTTPRequest::m_fullUrl
protected

Definition at line 171 of file torchttprequest.h.

QMap<QString,QString> TorcHTTPRequest::m_headers
protected

Definition at line 181 of file torchttprequest.h.

QString TorcHTTPRequest::m_method
protected

Definition at line 173 of file torchttprequest.h.

QString TorcHTTPRequest::m_path
protected

Definition at line 172 of file torchttprequest.h.

HTTPProtocol TorcHTTPRequest::m_protocol
protected

Definition at line 178 of file torchttprequest.h.

QMap<QString,QString> TorcHTTPRequest::m_queries
protected

Definition at line 182 of file torchttprequest.h.

QString TorcHTTPRequest::m_query
protected

Definition at line 174 of file torchttprequest.h.

QVector<QPair<quint64,quint64> > TorcHTTPRequest::m_ranges
protected

Definition at line 180 of file torchttprequest.h.

QString TorcHTTPRequest::m_redirectedTo
protected

Definition at line 175 of file torchttprequest.h.

HTTPRequestType TorcHTTPRequest::m_requestType
protected

Definition at line 177 of file torchttprequest.h.

QByteArray TorcHTTPRequest::m_responseContent
protected

Definition at line 194 of file torchttprequest.h.

QString TorcHTTPRequest::m_responseFile
protected

Definition at line 195 of file torchttprequest.h.

QMap<QString,QString> TorcHTTPRequest::m_responseHeaders
protected

Definition at line 196 of file torchttprequest.h.

HTTPStatus TorcHTTPRequest::m_responseStatus
protected

Definition at line 193 of file torchttprequest.h.

HTTPResponseType TorcHTTPRequest::m_responseType
protected

Definition at line 190 of file torchttprequest.h.

bool TorcHTTPRequest::m_secure
protected

Definition at line 184 of file torchttprequest.h.

HTTPType TorcHTTPRequest::m_type
protected

Definition at line 176 of file torchttprequest.h.


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