NuriaProject Framework  0.1
The NuriaProject Framework
Public Member Functions | List of all members
Nuria::HttpWriter Class Reference

Writer for HTTP data. More...

#include <httpwriter.hpp>

Public Member Functions

 HttpWriter ()
 
void addComplianceHeaders (HttpClient::HttpVersion version, HttpClient::HeaderMap &headers)
 
void addConnectionHeader (HttpClient::ConnectionMode mode, int count, int max, HttpClient::HeaderMap &headers)
 
void addTransferEncodingHeader (HttpClient::TransferMode mode, HttpClient::HeaderMap &headers)
 
void applyRangeHeaders (qint64 begin, qint64 end, qint64 totalLength, HttpClient::HeaderMap &headers)
 
QByteArray buildRangeHeader (qint64 begin, qint64 end, qint64 totalLength)
 
QByteArray dateTimeToHttpDateHeader (const QDateTime &dateTime)
 
QByteArray httpVersionToString (HttpClient::HttpVersion version)
 
QByteArray writeHttpHeaders (const HttpClient::HeaderMap &headers)
 
QByteArray writeResponseLine (HttpClient::HttpVersion version, int statusCode, const QByteArray &message)
 
QByteArray writeSetCookies (const HttpClient::Cookies &cookies)
 
QByteArray writeSetCookieValue (const QNetworkCookie &cookie)
 

Detailed Description

Writer for HTTP data.

Constructor & Destructor Documentation

Nuria::HttpWriter::HttpWriter ( )

Constructor.

Member Function Documentation

void Nuria::HttpWriter::addComplianceHeaders ( HttpClient::HttpVersion  version,
HttpClient::HeaderMap headers 
)

Adds missing HTTP headers to headers to make it compliant to version.

void Nuria::HttpWriter::addConnectionHeader ( HttpClient::ConnectionMode  mode,
int  count,
int  max,
HttpClient::HeaderMap headers 
)

Adds connectionValue to headers, if it is not empty, count is less than max and max is not -1. If the that condition is false, the function will add "Connection: close" instead.

void Nuria::HttpWriter::addTransferEncodingHeader ( HttpClient::TransferMode  mode,
HttpClient::HeaderMap headers 
)

Adds a Transfer-Encoding header to headers if mode and encoding indicate chunked transfer. If there's already a Transfer-Encoding header, it will be modified accordingly.

void Nuria::HttpWriter::applyRangeHeaders ( qint64  begin,
qint64  end,
qint64  totalLength,
HttpClient::HeaderMap headers 
)

If begin is -1 and totalLength is not -1, then a Content-Length will be put into headers. If begin and end are not -1, a Content-Range header is stored in headers. If no conditions are met, headers is left untouched.

Existing headers are not changed.

QByteArray Nuria::HttpWriter::buildRangeHeader ( qint64  begin,
qint64  end,
qint64  totalLength 
)

Returns the value for a Range header.

QByteArray Nuria::HttpWriter::dateTimeToHttpDateHeader ( const QDateTime &  dateTime)

Returns the formatted value for a Date header based on dateTime.

Note
dateTime is assumed to be in UTC.
QByteArray Nuria::HttpWriter::httpVersionToString ( HttpClient::HttpVersion  version)

Returns the full HTTP name of version.

QByteArray Nuria::HttpWriter::writeHttpHeaders ( const HttpClient::HeaderMap headers)

Takes headers and turns it into a HTTP header string.

QByteArray Nuria::HttpWriter::writeResponseLine ( HttpClient::HttpVersion  version,
int  statusCode,
const QByteArray &  message 
)

Returns the first line for a HTTP response header. If message is empty, HttpClient::httpStatusCodeName() will be used to generate an appropriate message.

QByteArray Nuria::HttpWriter::writeSetCookies ( const HttpClient::Cookies cookies)

Returns Set-Cookie header linedata from cookies.

QByteArray Nuria::HttpWriter::writeSetCookieValue ( const QNetworkCookie &  cookie)

Writes the value for a Set-Cookie HTTP header from cookie.

Note
This method is compliant with RFC 2109
As of Qt5.3, QNetworkCookie::toRawForm() is buggy which is the reason we're doing it in here manually.

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