Update httpserver to 1.6.5

This commit is contained in:
Luis Ángel San Martín
2016-06-22 19:09:04 +02:00
parent 44d7c892c1
commit 706e0921f3
22 changed files with 1491 additions and 1198 deletions

View File

@ -7,12 +7,14 @@
#define HTTPREQUEST_H
#include <QByteArray>
#include <QHostAddress>
#include <QTcpSocket>
#include <QMap>
#include <QMultiMap>
#include <QSettings>
#include <QTemporaryFile>
#include <QUuid>
#include "httpglobal.h"
/**
This object represents a single HTTP request. It reads the request
@ -31,9 +33,10 @@
The body is always a little larger than the file itself.
*/
class HttpRequest {
class DECLSPEC HttpRequest {
Q_DISABLE_COPY(HttpRequest)
friend class HttpSessionStore;
public:
/** Values for getStatus() */
@ -51,11 +54,12 @@ public:
virtual ~HttpRequest();
/**
Read the request from a socket. This method must be called repeatedly
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.
@param socket Source of the data
*/
void readFromSocket(QTcpSocket& socket);
void readFromSocket(QTcpSocket* socket);
/**
Get the status of this reqeust.
@ -69,12 +73,15 @@ public:
/** Get the decoded path of the HTPP request (e.g. "/index.html") */
QByteArray getPath() const;
/** Get the raw path of the HTTP request (e.g. "/file%20with%20spaces.html") */
const QByteArray& getRawPath() const;
/** Get the version of the HTPP request (e.g. "HTTP/1.1") */
QByteArray getVersion() const;
/**
Get the value of a HTTP request header.
@param name Name of the header
@param name Name of the header, not case-senitive.
@return If the header occurs multiple times, only the last
one is returned.
*/
@ -82,16 +89,19 @@ public:
/**
Get the values of a HTTP request header.
@param name Name of the header
@param name Name of the header, not case-senitive.
*/
QList<QByteArray> getHeaders(const QByteArray& name) const;
/** Get all HTTP request headers */
/**
* Get all HTTP request headers. Note that the header names
* are returned in lower-case.
*/
QMultiMap<QByteArray,QByteArray> getHeaderMap() const;
/**
Get the value of a HTTP request parameter.
@param name Name of the parameter
@param name Name of the parameter, case-sensitive.
@return If the parameter occurs multiple times, only the last
one is returned.
*/
@ -99,14 +109,14 @@ public:
/**
Get the values of a HTTP request parameter.
@param name Name of the parameter
@param name Name of the parameter, case-sensitive.
*/
QList<QByteArray> getParameters(const QByteArray& name) const;
/** Get all HTTP request parameters */
/** Get all HTTP request parameters. */
QMultiMap<QByteArray,QByteArray> getParameterMap() const;
/** Get the HTTP request body */
/** Get the HTTP request body. */
QByteArray getBody() const;
/**
@ -125,17 +135,24 @@ public:
For uploaded files, the method getParameters() returns
the original fileName as provided by the calling web browser.
*/
QTemporaryFile* getUploadedFile(const QByteArray fieldName);
QTemporaryFile* getUploadedFile(const QByteArray fieldName) const;
/**
Get the value of a cookie
Get the value of a cookie.
@param name Name of the cookie
*/
QByteArray getCookie(const QByteArray& name) const;
/** Get the map of cookies */
/** Get all cookies. */
QMap<QByteArray,QByteArray>& getCookieMap();
/**
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).
*/
QHostAddress getPeerAddress() const;
private:
/** Request headers */
@ -163,11 +180,14 @@ private:
QByteArray version;
/**
Status of this request.
Status of this request. For the state engine.
@see RequestStatus
*/
RequestStatus status;
/** Address of the connected peer. */
QHostAddress peerAddress;
/** Maximum size of requests in bytes. */
int maxSize;
@ -193,13 +213,13 @@ private:
void parseMultiPartFile();
/** Sub-procedure of readFromSocket(), read the first line of a request. */
void readRequest(QTcpSocket& socket);
void readRequest(QTcpSocket* socket);
/** Sub-procedure of readFromSocket(), read header lines. */
void readHeader(QTcpSocket& socket);
void readHeader(QTcpSocket* socket);
/** Sub-procedure of readFromSocket(), read the request body. */
void readBody(QTcpSocket& socket);
void readBody(QTcpSocket* socket);
/** Sub-procedure of readFromSocket(), extract and decode request parameters. */
void decodeRequestParams();
@ -207,6 +227,9 @@ private:
/** Sub-procedure of readFromSocket(), extract cookies from headers */
void extractCookies();
/** Buffer for collecting characters of request and header lines */
QByteArray lineBuffer;
};
#endif // HTTPREQUEST_H