Public Types | Public Member Functions | Static Public Member Functions | Friends

HttpRequest Class Reference

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

#include <httprequest.h>

List of all members.

Public Types

enum  RequestStatus {
  waitForRequest, waitForHeader, waitForBody, complete,
  abort
}
 

Values for getStatus().


Public Member Functions

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

Static Public Member Functions

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

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 34 of file httprequest.h.


Constructor & Destructor Documentation

HttpRequest::HttpRequest ( QSettings *  settings  ) 

Constructor.

Parameters:
settings Configuration settings

Definition at line 11 of file httprequest.cpp.


Member Function Documentation

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

Get the value of a cookie.

Parameters:
name Name of the cookie

Definition at line 427 of file httprequest.cpp.

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

Get the value of a HTTP request header.

Parameters:
name Name of the header
Returns:
If the header occurs multiple times, only the last one is returned.

Definition at line 271 of file httprequest.cpp.

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

Get the values of a HTTP request header.

Parameters:
name Name of the header

Definition at line 275 of file httprequest.cpp.

QByteArray HttpRequest::getMethod (  )  const

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

"GET")

Definition at line 256 of file httprequest.cpp.

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

Get the value of a HTTP request parameter.

Parameters:
name Name of the parameter
Returns:
If the parameter occurs multiple times, only the last one is returned.

Definition at line 283 of file httprequest.cpp.

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

Get the values of a HTTP request parameter.

Parameters:
name Name of the parameter

Definition at line 287 of file httprequest.cpp.

QByteArray HttpRequest::getPath (  )  const

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

"/index.html")

Definition at line 261 of file httprequest.cpp.

HttpRequest::RequestStatus HttpRequest::getStatus (  )  const

Get the status of this reqeust.

See also:
RequestStatus

Definition at line 251 of file httprequest.cpp.

QTemporaryFile * HttpRequest::getUploadedFile ( const QByteArray  fieldName  ) 

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.

Definition at line 423 of file httprequest.cpp.

QByteArray HttpRequest::getVersion (  )  const

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

"HTTP/1.1")

Definition at line 266 of file httprequest.cpp.

void HttpRequest::readFromSocket ( QTcpSocket &  socket  ) 

Read the request from a socket.

This method must be called repeatedly until the status is RequestStatus::complete or RequestStatus::abort.

Parameters:
socket Source of the data

Definition at line 227 of file httprequest.cpp.

QByteArray HttpRequest::urlDecode ( const QByteArray  source  )  [static]

Decode an URL parameter.

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

Parameters:
source The url encoded string

Definition at line 299 of file httprequest.cpp.


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