SDRAngel
4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
|
#include <httprequest.h>
Public Types | |
enum | RequestStatus { waitForRequest, waitForHeader, waitForBody, complete, abort } |
Public Member Functions | |
HttpRequest (QSettings *settings) | |
HttpRequest (const HttpListenerSettings *settings) | |
virtual | ~HttpRequest () |
void | readFromSocket (QTcpSocket *socket) |
RequestStatus | getStatus () const |
QByteArray | getMethod () const |
QByteArray | getPath () const |
const QByteArray & | getRawPath () const |
QByteArray | getVersion () const |
QByteArray | getHeader (const QByteArray &name) const |
QList< QByteArray > | getHeaders (const QByteArray &name) const |
QMultiMap< QByteArray, QByteArray > | getHeaderMap () const |
QByteArray | getParameter (const QByteArray &name) const |
QList< QByteArray > | getParameters (const QByteArray &name) const |
QMultiMap< QByteArray, QByteArray > | getParameterMap () const |
QByteArray | getBody () const |
QTemporaryFile * | getUploadedFile (const QByteArray fieldName) const |
QByteArray | getCookie (const QByteArray &name) const |
QMap< QByteArray, QByteArray > & | getCookieMap () |
QHostAddress | getPeerAddress () const |
Static Public Member Functions | |
static QByteArray | urlDecode (const QByteArray source) |
Private Member Functions | |
void | parseMultiPartFile () |
void | readRequest (QTcpSocket *socket) |
void | readHeader (QTcpSocket *socket) |
void | readBody (QTcpSocket *socket) |
void | decodeRequestParams () |
void | extractCookies () |
Private Attributes | |
QMultiMap< QByteArray, QByteArray > | headers |
QMultiMap< QByteArray, QByteArray > | parameters |
QMap< QByteArray, QTemporaryFile * > | uploadedFiles |
QMap< QByteArray, QByteArray > | cookies |
QByteArray | bodyData |
QByteArray | method |
QByteArray | path |
QByteArray | version |
RequestStatus | status |
QHostAddress | peerAddress |
int | maxSize |
int | maxMultiPartSize |
int | currentSize |
int | expectedBodySize |
QByteArray | currentHeader |
QByteArray | boundary |
QTemporaryFile * | tempFile |
QByteArray | lineBuffer |
bool | useQtSettings |
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 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 41 of file httprequest.h.
Values for getStatus()
Enumerator | |
---|---|
waitForRequest | |
waitForHeader | |
waitForBody | |
complete | |
abort |
Definition at line 48 of file httprequest.h.
HttpRequest::HttpRequest | ( | QSettings * | settings | ) |
Constructor.
settings | Configuration settings |
Definition at line 15 of file httprequest.cpp.
References currentSize, expectedBodySize, maxMultiPartSize, maxSize, status, tempFile, and waitForRequest.
HttpRequest::HttpRequest | ( | const HttpListenerSettings * | settings | ) |
Constructor.
settings | Configuration settings as a structure |
Definition at line 27 of file httprequest.cpp.
References currentSize, expectedBodySize, qtwebapp::HttpListenerSettings::maxMultiPartSize, maxMultiPartSize, qtwebapp::HttpListenerSettings::maxRequestSize, maxSize, status, tempFile, and waitForRequest.
|
virtual |
Destructor.
Definition at line 542 of file httprequest.cpp.
References tempFile, and uploadedFiles.
|
private |
Sub-procedure of readFromSocket(), extract and decode request parameters.
Definition at line 228 of file httprequest.cpp.
References bodyData, headers, parameters, path, and urlDecode().
Referenced by readFromSocket().
|
private |
Sub-procedure of readFromSocket(), extract cookies from headers
Definition at line 274 of file httprequest.cpp.
References cookies, headers, and qtwebapp::HttpCookie::splitCSV().
Referenced by readFromSocket().
QByteArray HttpRequest::getBody | ( | ) | const |
Get the HTTP request body.
Definition at line 396 of file httprequest.cpp.
References bodyData.
Referenced by WebAPIRequestMapper::devicesetChannelService(), WebAPIRequestMapper::devicesetChannelSettingsService(), WebAPIRequestMapper::devicesetDeviceService(), WebAPIRequestMapper::devicesetDeviceSettingsService(), WebAPIRequestMapper::instanceAMBEDevicesService(), WebAPIRequestMapper::instanceAudioInputParametersService(), WebAPIRequestMapper::instanceAudioOutputParametersService(), WebAPIRequestMapper::instanceLocationService(), WebAPIRequestMapper::instanceLoggingService(), WebAPIRequestMapper::instancePresetFileService(), and WebAPIRequestMapper::instancePresetService().
QByteArray HttpRequest::getCookie | ( | const QByteArray & | name | ) | const |
Get the value of a cookie.
name | Name of the cookie |
Definition at line 568 of file httprequest.cpp.
References cookies.
Referenced by qtwebapp::HttpSessionStore::getSessionId().
QMap< QByteArray, QByteArray > & HttpRequest::getCookieMap | ( | ) |
Get all cookies.
Get the map of cookies
Definition at line 574 of file httprequest.cpp.
References cookies.
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 366 of file httprequest.cpp.
References headers.
Referenced by qtwebapp::HttpConnectionHandler::read().
QMultiMap< QByteArray, QByteArray > HttpRequest::getHeaderMap | ( | ) | const |
Get all HTTP request headers. Note that the header names are returned in lower-case.
Definition at line 376 of file httprequest.cpp.
References headers.
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 371 of file httprequest.cpp.
References headers.
QByteArray HttpRequest::getMethod | ( | ) | const |
Get the method of the HTTP request (e.g. "GET")
Definition at line 342 of file httprequest.cpp.
References method.
Referenced by WebAPIRequestMapper::devicesetChannelIndexService(), WebAPIRequestMapper::devicesetChannelReportService(), WebAPIRequestMapper::devicesetChannelService(), WebAPIRequestMapper::devicesetChannelSettingsService(), WebAPIRequestMapper::devicesetChannelsReportService(), WebAPIRequestMapper::devicesetDeviceReportService(), WebAPIRequestMapper::devicesetDeviceRunService(), WebAPIRequestMapper::devicesetDeviceService(), WebAPIRequestMapper::devicesetDeviceSettingsService(), WebAPIRequestMapper::devicesetFocusService(), WebAPIRequestMapper::devicesetService(), WebAPIRequestMapper::instanceAMBEDevicesService(), WebAPIRequestMapper::instanceAMBESerialService(), WebAPIRequestMapper::instanceAudioInputCleanupService(), WebAPIRequestMapper::instanceAudioInputParametersService(), WebAPIRequestMapper::instanceAudioOutputCleanupService(), WebAPIRequestMapper::instanceAudioOutputParametersService(), WebAPIRequestMapper::instanceAudioService(), WebAPIRequestMapper::instanceChannelsService(), WebAPIRequestMapper::instanceConfigService(), WebAPIRequestMapper::instanceDeviceSetService(), WebAPIRequestMapper::instanceDeviceSetsService(), WebAPIRequestMapper::instanceDevicesService(), WebAPIRequestMapper::instanceLocationService(), WebAPIRequestMapper::instanceLoggingService(), WebAPIRequestMapper::instancePresetFileService(), WebAPIRequestMapper::instancePresetService(), WebAPIRequestMapper::instancePresetsService(), WebAPIRequestMapper::instanceSummaryService(), qtwebapp::HttpConnectionHandler::read(), WebAPIRequestMapper::service(), and qtwebapp::HttpRequestHandler::service().
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 381 of file httprequest.cpp.
References parameters.
Referenced by WebAPIRequestMapper::instanceChannelsService(), WebAPIRequestMapper::instanceDeviceSetService(), and WebAPIRequestMapper::instanceDevicesService().
QMultiMap< QByteArray, QByteArray > HttpRequest::getParameterMap | ( | ) | const |
Get all HTTP request parameters.
Definition at line 391 of file httprequest.cpp.
References parameters.
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 386 of file httprequest.cpp.
References parameters.
QByteArray HttpRequest::getPath | ( | ) | const |
Get the decoded path of the HTPP request (e.g. "/index.html")
Definition at line 348 of file httprequest.cpp.
References path, and urlDecode().
Referenced by qtwebapp::HttpConnectionHandler::read(), WebAPIRequestMapper::service(), qtwebapp::HttpRequestHandler::service(), and qtwebapp::StaticFileController::service().
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 584 of file httprequest.cpp.
References peerAddress.
Referenced by qtwebapp::HttpConnectionHandler::read().
const QByteArray & HttpRequest::getRawPath | ( | ) | const |
Get the raw path of the HTTP request (e.g. "/file%20with%20spaces.html")
Definition at line 354 of file httprequest.cpp.
References path.
HttpRequest::RequestStatus HttpRequest::getStatus | ( | ) | const |
Get the status of this reqeust.
Definition at line 336 of file httprequest.cpp.
References status.
Referenced by qtwebapp::HttpConnectionHandler::read().
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 563 of file httprequest.cpp.
References uploadedFiles.
QByteArray HttpRequest::getVersion | ( | ) | const |
Get the version of the HTPP request (e.g. "HTTP/1.1")
Definition at line 360 of file httprequest.cpp.
References version.
Referenced by qtwebapp::HttpConnectionHandler::read(), and qtwebapp::HttpRequestHandler::service().
|
private |
Parse the multipart body, that has been stored in the temp file.
Definition at line 420 of file httprequest.cpp.
References boundary, currentSize, parameters, tempFile, and uploadedFiles.
Referenced by readBody().
|
private |
Sub-procedure of readFromSocket(), read the request body.
Definition at line 165 of file httprequest.cpp.
References abort, bodyData, boundary, complete, currentSize, expectedBodySize, maxMultiPartSize, parseMultiPartFile(), status, and tempFile.
Referenced by 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.
socket | Source of the data |
Definition at line 306 of file httprequest.cpp.
References abort, boundary, complete, currentSize, decodeRequestParams(), extractCookies(), maxMultiPartSize, maxSize, readBody(), readHeader(), readRequest(), status, waitForBody, waitForHeader, and waitForRequest.
Referenced by qtwebapp::HttpConnectionHandler::read().
|
private |
Sub-procedure of readFromSocket(), read header lines.
Definition at line 75 of file httprequest.cpp.
References abort, boundary, complete, currentHeader, currentSize, expectedBodySize, headers, lineBuffer, maxMultiPartSize, maxSize, status, and waitForBody.
Referenced by readFromSocket().
|
private |
Sub-procedure of readFromSocket(), read the first line of a request.
Definition at line 40 of file httprequest.cpp.
References abort, currentSize, lineBuffer, maxSize, method, path, peerAddress, status, version, and waitForHeader.
Referenced by readFromSocket().
|
static |
Decode an URL parameter. E.g. replace "%23" by '#' and replace '+' by ' '.
source | The url encoded strings |
Definition at line 401 of file httprequest.cpp.
Referenced by decodeRequestParams(), and getPath().
|
friend |
Definition at line 43 of file httprequest.h.
|
private |
Storage for raw body data
Definition at line 182 of file httprequest.h.
Referenced by decodeRequestParams(), getBody(), and readBody().
|
private |
Boundary of multipart/form-data body. Empty if there is no such header
Definition at line 218 of file httprequest.h.
Referenced by parseMultiPartFile(), readBody(), readFromSocket(), and readHeader().
|
private |
Received cookies
Definition at line 179 of file httprequest.h.
Referenced by extractCookies(), getCookie(), and getCookieMap().
|
private |
Name of the current header, or empty if no header is being processed
Definition at line 215 of file httprequest.h.
Referenced by readHeader().
|
private |
Current size
Definition at line 209 of file httprequest.h.
Referenced by HttpRequest(), parseMultiPartFile(), readBody(), readFromSocket(), readHeader(), and readRequest().
|
private |
Expected size of body
Definition at line 212 of file httprequest.h.
Referenced by HttpRequest(), readBody(), and readHeader().
|
private |
Request headers
Definition at line 170 of file httprequest.h.
Referenced by decodeRequestParams(), extractCookies(), getHeader(), getHeaderMap(), getHeaders(), and readHeader().
|
private |
Buffer for collecting characters of request and header lines
Definition at line 242 of file httprequest.h.
Referenced by readHeader(), and readRequest().
|
private |
Maximum allowed size of multipart forms in bytes.
Definition at line 206 of file httprequest.h.
Referenced by HttpRequest(), readBody(), readFromSocket(), and readHeader().
|
private |
Maximum size of requests in bytes.
Definition at line 203 of file httprequest.h.
Referenced by HttpRequest(), readFromSocket(), readHeader(), and readRequest().
|
private |
Request method
Definition at line 185 of file httprequest.h.
Referenced by getMethod(), and readRequest().
|
private |
Parameters of the request
Definition at line 173 of file httprequest.h.
Referenced by decodeRequestParams(), getParameter(), getParameterMap(), getParameters(), and parseMultiPartFile().
|
private |
Request path (in raw encoded format)
Definition at line 188 of file httprequest.h.
Referenced by decodeRequestParams(), getPath(), getRawPath(), and readRequest().
|
private |
Address of the connected peer.
Definition at line 200 of file httprequest.h.
Referenced by getPeerAddress(), and readRequest().
|
private |
Status of this request. For the state engine.
Definition at line 197 of file httprequest.h.
Referenced by getStatus(), HttpRequest(), readBody(), readFromSocket(), readHeader(), and readRequest().
|
private |
Temp file, that is used to store the multipart/form-data body
Definition at line 221 of file httprequest.h.
Referenced by HttpRequest(), parseMultiPartFile(), readBody(), and ~HttpRequest().
|
private |
Uploaded files of the request, key is the field name.
Definition at line 176 of file httprequest.h.
Referenced by getUploadedFile(), parseMultiPartFile(), and ~HttpRequest().
|
private |
Settings flag
Definition at line 245 of file httprequest.h.
|
private |
Request protocol version
Definition at line 191 of file httprequest.h.
Referenced by getVersion(), and readRequest().