cutelyst  4.5.1
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
Cutelyst::EngineRequest Class Referenceabstract
Inheritance diagram for Cutelyst::EngineRequest:

Public Types

enum  StatusFlag : quint8 {
  InitialState , FinalizedHeaders , IOWrite , Chunked ,
  ChunkedDone , Async , Finalized
}
 

Public Member Functions

void finalize ()
 
virtual void finalizeBody ()
 
virtual void finalizeCookies ()
 
virtual void finalizeError ()
 
virtual bool finalizeHeaders ()
 
void setPath (char *rawPath, const int len)
 
void setPath (QByteArray &path)
 
virtual bool webSocketClose (quint16 code, const QString &reason)
 
bool webSocketHandshake (const QByteArray &key, const QByteArray &origin, const QByteArray &protocol)
 
virtual bool webSocketSendBinaryMessage (const QByteArray &message)
 
virtual bool webSocketSendPing (const QByteArray &payload)
 
virtual bool webSocketSendTextMessage (const QString &message)
 
qint64 write (const char *data, qint64 len)
 

Public Attributes

QIODevicebody
 
Contextcontext
 
Headers headers
 
bool isSecure
 
QByteArray method
 
QString path
 
QByteArray protocol
 
QByteArray query
 
QHostAddress remoteAddress
 
quint16 remotePort
 
QString remoteUser
 
QByteArray serverAddress
 
TimePointSteady startOfRequest
 
Status status
 

Protected Member Functions

virtual qint64 doWrite (const char *data, qint64 len)=0
 
virtual void processingFinished ()
 
virtual bool webSocketHandshakeDo (const QByteArray &key, const QByteArray &origin, const QByteArray &protocol)
 
virtual bool writeHeaders (quint16 status, const Headers &headers)=0
 

Friends

class Engine
 

Detailed Description

Definition at line 27 of file enginerequest.h.

Member Function Documentation

◆ doWrite()

virtual qint64 Cutelyst::EngineRequest::doWrite ( const char *  data,
qint64  len 
)
protectedpure virtual

Reimplement this to do the RAW writing to the client

Implemented in Cutelyst::H2Stream, Cutelyst::ProtoRequestHttp, and Cutelyst::ProtoRequestFastCGI.

Referenced by finalizeBody(), and write().

◆ finalize()

void EngineRequest::finalize ( )

Called by Application to deal with finalizing cookies, headers and body

Definition at line 79 of file enginerequest.cpp.

References context, Cutelyst::Context::error(), finalizeBody(), finalizeError(), finalizeHeaders(), processingFinished(), and status.

◆ finalizeBody()

void EngineRequest::finalizeBody ( )
virtual

◆ finalizeCookies()

void EngineRequest::finalizeCookies ( )
virtual

Reimplement if you need a custom way to Set-Cookie, the default implementation writes them to c->res()->headers()

Definition at line 93 of file enginerequest.cpp.

References context, Cutelyst::Response::cookies(), headers, Cutelyst::Response::headers(), Cutelyst::Headers::pushHeader(), and Cutelyst::Context::response().

Referenced by finalizeHeaders().

◆ finalizeError()

void EngineRequest::finalizeError ( )
virtual

Engines should overwrite this if they want to to make custom error messages. Default implementation render an html with errors.

Definition at line 59 of file enginerequest.cpp.

References body, context, Cutelyst::Context::errors(), QStringList::join(), Cutelyst::Context::response(), Cutelyst::Response::setBody(), Cutelyst::Response::setContentType(), and Cutelyst::Response::setStatus().

Referenced by finalize().

◆ finalizeHeaders()

bool EngineRequest::finalizeHeaders ( )
virtual

Finalize the headers, and call doWriteHeader(), reimplemententions must call this first

Definition at line 103 of file enginerequest.cpp.

References context, finalizeCookies(), headers, Cutelyst::Response::headers(), Cutelyst::Context::response(), Cutelyst::Headers::setContentLength(), Cutelyst::Response::size(), status, Cutelyst::Response::status(), and writeHeaders().

Referenced by finalize().

◆ processingFinished()

void EngineRequest::processingFinished ( )
protectedvirtual

This is called when the Application chain is finished processing this request, here the request can send final bytes to the client or do a clean up.

Default implementation deletes both body and context.

If a WebSocket upgrade was made then you will want to keep the context object around.

Reimplemented in Cutelyst::H2Stream, Cutelyst::ProtoRequestHttp, and Cutelyst::ProtoRequestFastCGI.

Definition at line 187 of file enginerequest.cpp.

Referenced by finalize().

◆ setPath()

void EngineRequest::setPath ( char *  rawPath,
const int  len 
)

This method sets the path and already does the decoding so that it is done a single time.

The path requested by the user agent '/index', MUST have a leading slash

Definition at line 201 of file enginerequest.cpp.

References QString::fromLatin1(), QString::fromUtf8(), path, QString::prepend(), and QString::startsWith().

◆ write()

qint64 EngineRequest::write ( const char *  data,
qint64  len 
)

◆ writeHeaders()

virtual bool Cutelyst::EngineRequest::writeHeaders ( quint16  status,
const Headers headers 
)
protectedpure virtual

Reimplement this to write the headers back to the client

Implemented in Cutelyst::H2Stream, Cutelyst::ProtoRequestHttp, and Cutelyst::ProtoRequestFastCGI.

Referenced by finalizeHeaders().

Member Data Documentation

◆ body

QIODevice* Cutelyst::EngineRequest::body

The QIODevice containing the body (if any) of the request

Note
It's deleted when Context gets deleted

Definition at line 169 of file enginerequest.h.

Referenced by Cutelyst::Request::Request(), finalizeBody(), and finalizeError().

◆ context

Context* Cutelyst::EngineRequest::context

The Cutelyst::Context of this request

Note
It's deleted on processingFinished() or destructor

Definition at line 173 of file enginerequest.h.

Referenced by finalize(), finalizeBody(), finalizeCookies(), finalizeError(), finalizeHeaders(), and Cutelyst::Application::handleRequest().

◆ headers

◆ isSecure

bool Cutelyst::EngineRequest::isSecure

If the connection is secure HTTPS

Definition at line 185 of file enginerequest.h.

◆ method

QByteArray Cutelyst::EngineRequest::method

The method used (GET, POST...)

Definition at line 142 of file enginerequest.h.

◆ path

QString Cutelyst::EngineRequest::path

Call setPath() instead

Definition at line 145 of file enginerequest.h.

Referenced by setPath().

◆ protocol

QByteArray Cutelyst::EngineRequest::protocol

The protocol requested by the user agent 'HTTP1/1'

Definition at line 151 of file enginerequest.h.

Referenced by Cutelyst::ProtoRequestHttp::writeHeaders().

◆ query

QByteArray Cutelyst::EngineRequest::query

The query string requested by the user agent 'foo=bar&baz'

Definition at line 148 of file enginerequest.h.

◆ remoteAddress

QHostAddress Cutelyst::EngineRequest::remoteAddress

The remote/client address

Definition at line 159 of file enginerequest.h.

◆ remotePort

quint16 Cutelyst::EngineRequest::remotePort

The remote/client port

Definition at line 179 of file enginerequest.h.

◆ remoteUser

QString Cutelyst::EngineRequest::remoteUser

The remote user name set by a front web server

Definition at line 162 of file enginerequest.h.

◆ serverAddress

QByteArray Cutelyst::EngineRequest::serverAddress

The server address which the server is listening to, usually the 'Host' header but if that's not present should be filled with the server address

Definition at line 156 of file enginerequest.h.

◆ startOfRequest

TimePointSteady Cutelyst::EngineRequest::startOfRequest

The timepoint of the start of request

Definition at line 176 of file enginerequest.h.

◆ status