Stellarium 0.15.2
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Friends
HttpRequest Class Reference

This object represents a single HTTP request. More...

#include <httprequest.h>

Public Types

enum  RequestStatus {
  waitForRequest, waitForHeader, waitForBody, complete,
  abort
}
 Values for getStatus() More...
 

Public Member Functions

 HttpRequest (const int maxRequestSize, const int maxMultiPartSize)
 Constructor. More...
 
virtual ~HttpRequest ()
 Destructor. More...
 
void readFromSocket (QTcpSocket *socket)
 Read the HTTP request from a socket. More...
 
RequestStatus getStatus () const
 Get the status of this reqeust. More...
 
QByteArray getMethod () const
 Get the method of the HTTP request (e.g. More...
 
QByteArray getPath () const
 Get the decoded path of the HTPP request (e.g. More...
 
const QByteArray & getRawPath () const
 Get the raw path of the HTTP request (e.g. More...
 
QByteArray getVersion () const
 Get the version of the HTPP request (e.g. More...
 
QByteArray getHeader (const QByteArray &name) const
 Get the value of a HTTP request header. More...
 
QList< QByteArray > getHeaders (const QByteArray &name) const
 Get the values of a HTTP request header. More...
 
QMultiMap< QByteArray, QByteArray > getHeaderMap () const
 Get all HTTP request headers. More...
 
QByteArray getParameter (const QByteArray &name) const
 Get the value of a HTTP request parameter. More...
 
QList< QByteArray > getParameters (const QByteArray &name) const
 Get the values of a HTTP request parameter. More...
 
QMultiMap< QByteArray, QByteArray > getParameterMap () const
 Get all HTTP request parameters. More...
 
QByteArray getBody () const
 Get the HTTP request body. More...
 
QTemporaryFile * getUploadedFile (const QByteArray fieldName) const
 Get an uploaded file. More...
 
QByteArray getCookie (const QByteArray &name) const
 Get the value of a cookie. More...
 
QMap< QByteArray, QByteArray > & getCookieMap ()
 Get all cookies. More...
 
QHostAddress getPeerAddress () const
 Get the address of the connected client. More...
 

Static Public Member Functions

static QByteArray urlDecode (const QByteArray source)
 Decode an URL parameter. More...
 

Friends

class HttpSessionStore
 

Detailed Description

This object represents a single HTTP request.

It reads the request from a TCP socket and provides getters for the individual parts of the request.

The follwing config settings are required:

maxRequestSize=16000
maxMultiPartSize=1000000

MaxRequestSize is the maximum size of a HTTP request. In case of multipart/form-data requests (also known as file-upload), the maximum size of the body must not exceed maxMultiPartSize. The body is always a little larger than the file itself.

Definition at line 36 of file httprequest.h.

Member Enumeration Documentation

Values for getStatus()

Definition at line 43 of file httprequest.h.

Constructor & Destructor Documentation

HttpRequest::HttpRequest ( const int  maxRequestSize,
const int  maxMultiPartSize 
)

Constructor.

Parameters
settingsConfiguration settings
virtual HttpRequest::~HttpRequest ( )
virtual

Destructor.

Member Function Documentation

QByteArray HttpRequest::getBody ( ) const

Get the HTTP request body.

QByteArray HttpRequest::getCookie ( const QByteArray &  name) const

Get the value of a cookie.

Parameters
nameName of the cookie
QMap<QByteArray,QByteArray>& HttpRequest::getCookieMap ( )

Get all cookies.

QByteArray HttpRequest::getHeader ( const QByteArray &  name) const

Get the value of a HTTP request header.

Parameters
nameName of the header
Returns
If the header occurs multiple times, only the last one is returned.
QMultiMap<QByteArray,QByteArray> HttpRequest::getHeaderMap ( ) const

Get all HTTP request headers.

QList<QByteArray> HttpRequest::getHeaders ( const QByteArray &  name) const

Get the values of a HTTP request header.

Parameters
nameName of the header
QByteArray HttpRequest::getMethod ( ) const

Get the method of the HTTP request (e.g.

"GET")

QByteArray HttpRequest::getParameter ( const QByteArray &  name) const

Get the value of a HTTP request parameter.

Parameters
nameName of the parameter
Returns
If the parameter occurs multiple times, only the last one is returned.
QMultiMap<QByteArray,QByteArray> HttpRequest::getParameterMap ( ) const

Get all HTTP request parameters.

QList<QByteArray> HttpRequest::getParameters ( const QByteArray &  name) const

Get the values of a HTTP request parameter.

Parameters
nameName of the parameter
QByteArray HttpRequest::getPath ( ) const

Get the decoded path of the HTPP request (e.g.

"/index.html")

QHostAddress HttpRequest::getPeerAddress ( ) const

Get the address of the connected client.

Note that multiple clients may have the same IP address, if they share an internet connection (which is very common).

const QByteArray& HttpRequest::getRawPath ( ) const

Get the raw path of the HTTP request (e.g.

"/file%20with%20spaces.html")

RequestStatus HttpRequest::getStatus ( ) const

Get the status of this reqeust.

See also
RequestStatus
QTemporaryFile* HttpRequest::getUploadedFile ( const QByteArray  fieldName) const

Get an uploaded file.

The file is already open. It will be closed and deleted by the destructor of this HttpRequest object (after processing the request).

For uploaded files, the method getParameters() returns the original fileName as provided by the calling web browser.

QByteArray HttpRequest::getVersion ( ) const

Get the version of the HTPP request (e.g.

"HTTP/1.1")

void HttpRequest::readFromSocket ( QTcpSocket *  socket)

Read the HTTP request from a socket.

This method is called by the connection handler repeatedly until the status is RequestStatus::complete or RequestStatus::abort.

Parameters
socketSource of the data
static QByteArray HttpRequest::urlDecode ( const QByteArray  source)
static

Decode an URL parameter.

E.g. replace "%23" by '#' and replace '+' by ' '.

Parameters
sourceThe url encoded strings
See also
QUrl::toPercentEncoding for the reverse direction

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