Cutelyst  1.8.0
Signals | Public Member Functions | Properties | Friends | List of all members
Cutelyst::Request Class Reference
Inheritance diagram for Cutelyst::Request:
Inheritance graph
[legend]

Signals

void webSocketBinaryFrame (const QByteArray &message, bool isLastFrame, Context *c)
 Emitted when the websocket receives a binary frame, this is usefull for parsing big chunks of data without waiting till the whole message arives.
 
void webSocketBinaryMessage (const QByteArray &message, Context *c)
 Emitted when the websocket receives a binary message, this accounts for all binary frames till the last one.
 
void webSocketClosed (quint16 closeCode, const QString &reason)
 Emitted when the websocket receives a close frame, including a close code and a reason.
 
void webSocketPong (const QByteArray &payload, Context *c)
 Emitted when the websocket receives a pong frame, which might include a payload.
 
void webSocketTextFrame (const QString &message, bool isLastFrame, Context *c)
 Emitted when the websocket receives a text frame, this is usefull for parsing big chunks of data without waiting till the whole message arives.
 
void webSocketTextMessage (const QString &message, Context *c)
 Emitted when the websocket receives a text message, this accounts for all text frames till the last one.
 

Public Member Functions

 Request (RequestPrivate *prv)
 
QHostAddress address () const
 
QString addressString () const
 
QStringList args () const
 
QStringList arguments () const
 
QString base () const
 
QIODevice * body () const
 
QVariant bodyData () const
 
QString bodyParam (const QString &key, const QString &defaultValue=QString()) const
 
QString bodyParameter (const QString &key, const QString &defaultValue=QString()) const
 
ParamsMultiMap bodyParameters () const
 
QStringList bodyParameters (const QString &key) const
 
QVariantMap bodyParametersVariant () const
 
ParamsMultiMap bodyParams () const
 
QStringList bodyParams (const QString &key) const
 
QStringList captures () const
 
QString contentEncoding () const
 
QString contentType () const
 
QString cookie (const QString &name) const
 
QMap< QString, QString > cookies () const
 
Engineengine () const
 
void * engineData ()
 
QString header (const QString &key) const
 
Headers headers () const
 
QString hostname () const
 
bool isGet () const
 
bool isPost () const
 
ParamsMultiMap mangleParams (const ParamsMultiMap &args, bool append=false) const
 
QString match () const
 
QString method () const
 
QString param (const QString &key, const QString &defaultValue=QString()) const
 
ParamsMultiMap parameters () const
 
QVariantMap parametersVariant () const
 
QStringList params (const QString &key) const
 
ParamsMultiMap params () const
 
QString path () const
 
quint16 port () const
 
QString protocol () const
 
QString queryKeywords () const
 
QString queryParam (const QString &key, const QString &defaultValue=QString()) const
 
QString queryParameter (const QString &key, const QString &defaultValue=QString()) const
 
ParamsMultiMap queryParameters () const
 
QStringList queryParameters (const QString &key) const
 
QVariantMap queryParametersVariant () const
 
ParamsMultiMap queryParams () const
 
QStringList queryParams (const QString &key) const
 
QString referer () const
 
QString remoteUser () const
 
bool secure () const
 
void setArguments (const QStringList &arguments)
 
void setCaptures (const QStringList &captures)
 
void setMatch (const QString &match)
 
Uploadupload (const QString &name) const
 
QVector< Upload * > uploads () const
 
Uploads uploads (const QString &name) const
 
QMap< QString, Upload * > uploadsMap () const
 
QUrl uri () const
 
QUrl uriWith (const ParamsMultiMap &args, bool append=false) const
 
QString userAgent () const
 

Properties

QStringList args
 
QStringList arguments
 
QString base
 
QVariant bodyData
 
Cutelyst::ParamsMultiMap bodyParams
 
QString contentEncoding
 
QString contentType
 
QVariant headers
 
QString hostname
 
QString match
 
QString method
 
Cutelyst::ParamsMultiMap parameters
 
Cutelyst::ParamsMultiMap params
 
QString path
 
quint16 port
 
QString protocol
 
Cutelyst::ParamsMultiMap queryParams
 
QString referer
 
QString remoteUser
 
bool secure
 
QUrl uri
 
QString userAgent
 

Friends

class Application
 
class Dispatcher
 
class DispatchType
 

Detailed Description

Definition at line 43 of file request.h.

Constructor & Destructor Documentation

Cutelyst::Request::Request ( RequestPrivate *  prv)

Constructs a new Request object.

Member Function Documentation

QHostAddress Cutelyst::Request::address ( ) const

Returns the address of the client

QString Cutelyst::Request::addressString ( ) const

Returns the address as string of the client.

When using IPv6 sockets to listen to both IPv4 and IPv6 sockets the output of QHostAddress might be something like "::ffff:127.0.0.1", which is not a bug and a valid address, but from an application point of view this might not be interesting to have, so this function checks if it's possible to convert to an IPv4 address and returns "127.0.0.1".

QStringList Cutelyst::Request::args ( ) const
inline

Shortcut for arguments()

QStringList Cutelyst::Request::arguments ( ) const

Returns a list of string containing the arguments. For example, if your action was

class foo : public Cutelyst::Controller
{
public:
C_ATTR(bar, :Local)
void bar(Context *c);
};

and the URI for the request was http://.../foo/bar/bah, the string bah would be the first and only argument.

Arguments get automatically URI-unescaped for you.

QString Cutelyst::Request::base ( ) const

Returns Contains the URI base. This will always have a trailing slash. Note that the URI scheme (e.g., http vs. https) must be determined through heuristics; depending on your server configuration, it may be incorrect. See secure() for more info.

If your application was queried with the URI http://localhost:3000/some/path then base is http://localhost:3000/.

QIODevice* Cutelyst::Request::body ( ) const

Returns the message body of the request as passed by the Engine, this can even be a file if the Engine wants to.

QVariant Cutelyst::Request::bodyData ( ) const

Returns a QVariant representation of POST/PUT body data that is not classic HTML form data, such as JSON, XML, etc. By default, Cutelyst will parse incoming data of the type 'application/json' and return access to that data via this method.

You may define addition data_handlers.

If the POST is malformed in some way (such as undefined or not content that matches the content-type) we return a null QVariant.

If the POSTed content type does not match an available data handler, this will also return a null QVariant.

QString Cutelyst::Request::bodyParam ( const QString &  key,
const QString &  defaultValue = QString() 
) const
inline

Convenience method for geting a single body value passing a key and an optional default value

Definition at line 521 of file request.h.

QString Cutelyst::Request::bodyParameter ( const QString &  key,
const QString &  defaultValue = QString() 
) const
inline

Convenience method for geting a single body value passing a key and an optional default value

Definition at line 512 of file request.h.

ParamsMultiMap Cutelyst::Request::bodyParameters ( ) const

Returns a QMultiHash of body (POST) parameters

QStringList Cutelyst::Request::bodyParameters ( const QString &  key) const
inline

Convenience method for geting all body values passing a key

Definition at line 515 of file request.h.

References bodyParams().

QVariantMap Cutelyst::Request::bodyParametersVariant ( ) const

Returns a QVariantMap of body (POST) parameters, this method is expensive as it creates the map each time it's called, cache it's result instead of calling multiple times

ParamsMultiMap Cutelyst::Request::bodyParams ( ) const
inline

Short for bodyParameters()

Referenced by bodyParameters().

QStringList Cutelyst::Request::bodyParams ( const QString &  key) const
inline

Convenience method for geting all body values passing a key

Definition at line 524 of file request.h.

QStringList Cutelyst::Request::captures ( ) const

Captures

QString Cutelyst::Request::contentEncoding ( ) const
inline

Returns the Content-Encoding header

Referenced by params().

QString Cutelyst::Request::contentType ( ) const
inline

Returns the Content-Type header

Referenced by params().

QString Cutelyst::Request::cookie ( const QString &  name) const

Returns the cookie with the given name

QMap<QString, QString> Cutelyst::Request::cookies ( ) const

Returns all the cookies from the request

Engine* Cutelyst::Request::engine ( ) const

Returns the current Engine processing the requests.

void* Cutelyst::Request::engineData ( )

Returns the internal pointer that references a request in the engine. You should never use this method.

QString Cutelyst::Request::header ( const QString &  key) const
inline

Short for headers().header(key);

Definition at line 557 of file request.h.

References referer(), and userAgent().

Headers Cutelyst::Request::headers ( ) const

Returns the HTTP request headers

QString Cutelyst::Request::hostname ( ) const

Returns the hostname of the client, or null if not found or an error has happened.

This functions makes blocking call to do a reverse DNS lookup if the engine didn't set the hostname.

bool Cutelyst::Request::isGet ( ) const

Returns true if the request method is GET.

bool Cutelyst::Request::isPost ( ) const

Returns true if the request method is POST.

ParamsMultiMap Cutelyst::Request::mangleParams ( const ParamsMultiMap args,
bool  append = false 
) const

Returns a ParamsMultiMap of parameters stemming from the current request's params, plus the ones supplied. Keys for which no current param exists will be added, keys with null values will be removed and keys with existing params will be replaced. Note that you can supply a true value as the final argument to change behavior with regards to existing parameters, appending values rather than replacing them.

A quick example:

// URI query params foo=1
ParamsMultiMap params = request->mangleParams({ {"foo", "2"} });
// Result is query params of foo=2

versus append mode:

// URI query params foo=1
ParamsMultiMap params = request->mangleParams({ {"foo", "2"} }, true);
// Result is query params of foo=1&foo=2

This is the code behind uriWith().

QString Cutelyst::Request::match ( ) const

This contains the matching part of a Regex action. Otherwise it returns the same as 'action' (not a pointer but it's private name), except for default actions, which return an empty string.

QString Cutelyst::Request::method ( ) const

Returns the request method (GET, POST, HEAD, etc).

QString Cutelyst::Request::param ( const QString &  key,
const QString &  defaultValue = QString() 
) const
inline

Returns the value specified by key, it's equivalent to calling parameters().value().

Definition at line 542 of file request.h.

ParamsMultiMap Cutelyst::Request::parameters ( ) const

Returns a QMultiHash containing both the query parameters (GET) and the body parameters (POST)

QVariantMap Cutelyst::Request::parametersVariant ( ) const

Returns a QVariantMap of both query string (GET) and body (POST) parameters, this method is expensive as it creates the map each time it's called, cache it's result instead of calling multiple times

QStringList Cutelyst::Request::params ( const QString &  key) const
inline

Returns the values specified by key, it's equivalent to calling parameters().values().

Definition at line 545 of file request.h.

References contentEncoding(), contentType(), and params().

ParamsMultiMap Cutelyst::Request::params ( ) const
inline

Short for parameters()

Referenced by params().

QString Cutelyst::Request::path ( ) const

Returns the path, i.e. the part of the URI after base(), for the current request. for http://localhost/path/foo path will contain 'path/foo'

quint16 Cutelyst::Request::port ( ) const

Returns the originating port of the client

QString Cutelyst::Request::protocol ( ) const

Returns the protocol (HTTP/1.0 or HTTP/1.1) used for the current request.

QString Cutelyst::Request::queryKeywords ( ) const

Contains the keywords portion of a query string, when no '=' signs are present.

  • http://localhost/path?some+keywords
    c->request()->queryKeywords() will contain 'some keywords'
QString Cutelyst::Request::queryParam ( const QString &  key,
const QString &  defaultValue = QString() 
) const
inline

Convenience method for geting a single query value passing a key and an optional default value

Definition at line 536 of file request.h.

QString Cutelyst::Request::queryParameter ( const QString &  key,
const QString &  defaultValue = QString() 
) const
inline

Convenience method for geting a single query value passing a key and an optional default value

Definition at line 527 of file request.h.

ParamsMultiMap Cutelyst::Request::queryParameters ( ) const

Returns a QMultiHash containing the query string (GET) parameters

QStringList Cutelyst::Request::queryParameters ( const QString &  key) const
inline

Convenience method for geting all query values passing a key

Definition at line 530 of file request.h.

References queryParams().

QVariantMap Cutelyst::Request::queryParametersVariant ( ) const

Returns a QVariantMap of query string (GET) parameters, this method is expensive as it creates the map each time it's called, cache it's result instead of calling multiple times

ParamsMultiMap Cutelyst::Request::queryParams ( ) const
inline

Short for queryParameters()

Referenced by queryParameters().

QStringList Cutelyst::Request::queryParams ( const QString &  key) const
inline

Convenience method for geting all query values passing a key

Definition at line 539 of file request.h.

QString Cutelyst::Request::referer ( ) const
inline

referer Shortcut for header("Referer")

Referenced by header().

QString Cutelyst::Request::remoteUser ( ) const

Returns the value of the REMOTE_USER environment variable.

bool Cutelyst::Request::secure ( ) const

Returns true or false to indicate that a connection is secure (https), The reliability of it may depend on your server configuration, Cutelyst relies on the Engine to set this information which is used to build up uri().scheme(). The Engine itself might not be aware of a front HTTP server with https enabled.

void Cutelyst::Request::setArguments ( const QStringList &  arguments)

Defines the arguments of the request Useful for custom dispatchers and/or actions

void Cutelyst::Request::setCaptures ( const QStringList &  captures)

Defines the arguments of the request Useful for custom dispatchers and/or actions

void Cutelyst::Request::setMatch ( const QString &  match)

Defines the matching part of the request Useful for custom dispatchers

Upload * Cutelyst::Request::upload ( const QString &  name) const
inline

Returns the first Upload object for the given field, if no upload matches the field name this function returns 0.

Definition at line 566 of file request.h.

QVector<Upload *> Cutelyst::Request::uploads ( ) const

Returns a vector containing uploads

Uploads Cutelyst::Request::uploads ( const QString &  name) const

Returns all (if any) Upload objects for the given field.

QMap<QString, Upload *> Cutelyst::Request::uploadsMap ( ) const

Returns a map containing uploads, where their key is the field name.

QUrl Cutelyst::Request::uri ( ) const

Returns the uri as close as possible to what the user has in his browser url.

QUrl Cutelyst::Request::uriWith ( const ParamsMultiMap args,
bool  append = false 
) const

Returns a rewritten URI object for the current request. Key/value pairs passed in will override existing parameters. You can remove an existing parameter by passing in an undef value. Unmodified pairs will be preserved.

You may also pass an optional second parameter that puts uriWith() into append mode:

req->uriWith({ {"key", "value"} }, true);

See mangleParams() for an explanation of this behavior.

QString Cutelyst::Request::userAgent ( ) const
inline

Returns the user agent (browser) version string.

Referenced by header().