QtWebApp
stefanfrings::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()
 

Public Member Functions

 HttpRequest (const QSettings *settings)
 Constructor. More...
 
virtual ~HttpRequest ()
 Destructor.
 
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 38 of file httprequest.h.

Constructor & Destructor Documentation

◆ HttpRequest()

HttpRequest::HttpRequest ( const QSettings *  settings)

Constructor.

Parameters
settingsConfiguration settings

Definition at line 13 of file httprequest.cpp.

Member Function Documentation

◆ getBody()

QByteArray HttpRequest::getBody ( ) const

Get the HTTP request body.

Definition at line 379 of file httprequest.cpp.

◆ getCookie()

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

Get the value of a cookie.

Parameters
nameName of the cookie

Definition at line 556 of file httprequest.cpp.

◆ getCookieMap()

QMap< QByteArray, QByteArray > & HttpRequest::getCookieMap ( )

Get all cookies.

Get the map of cookies.

Definition at line 562 of file httprequest.cpp.

◆ getHeader()

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

Get the value of a HTTP request header.

Parameters
nameName of the header, not case-senitive.
Returns
If the header occurs multiple times, only the last one is returned.

Definition at line 349 of file httprequest.cpp.

◆ getHeaderMap()

QMultiMap< QByteArray, QByteArray > HttpRequest::getHeaderMap ( ) const

Get all HTTP request headers.

Note that the header names are returned in lower-case.

Definition at line 359 of file httprequest.cpp.

◆ getHeaders()

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

Get the values of a HTTP request header.

Parameters
nameName of the header, not case-senitive.

Definition at line 354 of file httprequest.cpp.

◆ getMethod()

QByteArray HttpRequest::getMethod ( ) const

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

"GET")

Definition at line 325 of file httprequest.cpp.

◆ getParameter()

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

Get the value of a HTTP request parameter.

Parameters
nameName of the parameter, case-sensitive.
Returns
If the parameter occurs multiple times, only the last one is returned.

Definition at line 364 of file httprequest.cpp.

◆ getParameterMap()

QMultiMap< QByteArray, QByteArray > HttpRequest::getParameterMap ( ) const

Get all HTTP request parameters.

Definition at line 374 of file httprequest.cpp.

◆ getParameters()

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

Get the values of a HTTP request parameter.

Parameters
nameName of the parameter, case-sensitive.

Definition at line 369 of file httprequest.cpp.

◆ getPath()

QByteArray HttpRequest::getPath ( ) const

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

"/index.html")

Definition at line 331 of file httprequest.cpp.

◆ getPeerAddress()

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).

Definition at line 572 of file httprequest.cpp.

◆ getRawPath()

const QByteArray & HttpRequest::getRawPath ( ) const

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

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

Definition at line 337 of file httprequest.cpp.

◆ getStatus()

HttpRequest::RequestStatus HttpRequest::getStatus ( ) const

Get the status of this reqeust.

See also
RequestStatus

Definition at line 319 of file httprequest.cpp.

◆ getUploadedFile()

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.

Definition at line 551 of file httprequest.cpp.

◆ getVersion()

QByteArray HttpRequest::getVersion ( ) const

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

"HTTP/1.1")

Definition at line 343 of file httprequest.cpp.

◆ readFromSocket()

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

Definition at line 289 of file httprequest.cpp.

◆ urlDecode()

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

Definition at line 384 of file httprequest.cpp.


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