QtWebApp
|
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. | |
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 |
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 following 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.
Definition at line 37 of file httprequest.h.
HttpRequest::HttpRequest | ( | const QSettings * | settings | ) |
Constructor.
settings | Configuration settings |
Definition at line 13 of file httprequest.cpp.
QByteArray HttpRequest::getBody | ( | ) | const |
QByteArray HttpRequest::getCookie | ( | const QByteArray & | name | ) | const |
Get the value of a cookie.
name | Name of the cookie |
Definition at line 559 of file httprequest.cpp.
QMap< QByteArray, QByteArray > & HttpRequest::getCookieMap | ( | ) |
QByteArray HttpRequest::getHeader | ( | const QByteArray & | name | ) | const |
Get the value of a HTTP request header.
name | Name of the header, not case-senitive. |
Definition at line 351 of file httprequest.cpp.
QMultiMap< QByteArray, QByteArray > HttpRequest::getHeaderMap | ( | ) | const |
Get all HTTP request headers.
Note that the header names are returned in lower-case.
Definition at line 361 of file httprequest.cpp.
QList< QByteArray > HttpRequest::getHeaders | ( | const QByteArray & | name | ) | const |
Get the values of a HTTP request header.
name | Name of the header, not case-senitive. |
Definition at line 356 of file httprequest.cpp.
QByteArray HttpRequest::getMethod | ( | ) | const |
QByteArray HttpRequest::getParameter | ( | const QByteArray & | name | ) | const |
Get the value of a HTTP request parameter.
name | Name of the parameter, case-sensitive. |
Definition at line 366 of file httprequest.cpp.
QList< QByteArray > HttpRequest::getParameters | ( | const QByteArray & | name | ) | const |
Get the values of a HTTP request parameter.
name | Name of the parameter, case-sensitive. |
Definition at line 371 of file httprequest.cpp.
QByteArray HttpRequest::getPath | ( | ) | const |
Get the decoded path of the HTPP request (e.g.
"/index.html")
Definition at line 333 of file httprequest.cpp.
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 575 of file httprequest.cpp.
const QByteArray & HttpRequest::getRawPath | ( | ) | const |
Get the raw path of the HTTP request (e.g.
"/file%20with%20spaces.html")
Definition at line 339 of file httprequest.cpp.
HttpRequest::RequestStatus HttpRequest::getStatus | ( | ) | const |
Get the status of this reqeust.
Definition at line 321 of file httprequest.cpp.
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 554 of file httprequest.cpp.
QByteArray HttpRequest::getVersion | ( | ) | const |
Get the version of the HTPP request (e.g.
"HTTP/1.1")
Definition at line 345 of file httprequest.cpp.
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.
socket | Source of the data |
Definition at line 291 of file httprequest.cpp.
|
static |
Decode an URL parameter.
E.g. replace "%23" by '#' and replace '+' by ' '.
source | The url encoded strings |
Definition at line 386 of file httprequest.cpp.