Cutelyst  1.5.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
Cutelyst::Response Class Reference
Inheritance diagram for Cutelyst::Response:
Inheritance graph
[legend]

Public Types

enum  HttpStatus {
  Continue, SwitchingProtocols, OK, Created,
  Accepted, NonAuthoritativeInformation, NoContent, ResetContent,
  PartialContent, MultipleChoices, MovedPermanently, Found,
  SeeOther, NotModified, UseProxy, TemporaryRedirect,
  PermanentRedirect, BadRequest, Unauthorized, PaymentRequired,
  Forbidden, NotFound, MethodNotAllowed, NotAcceptable,
  ProxyAuthenticationRequired, RequestTimeout, Conflict, Gone,
  LengthRequired, PreconditionFailed, RequestEntityTooLarge, RequestURITooLong,
  UnsupportedMediaType, RequestedRangeNotSatisfiable, ExpectationFailed, InternalServerError,
  NotImplemented, BadGateway, ServiceUnavailable, GatewayTimeout,
  HTTPVersionNotSupported, BandwidthLimitExceeded
}
 

Public Member Functions

QByteArray & body () Q_REQUIRED_RESULT
 
QIODevice * bodyDevice () const
 
QString contentEncoding () const
 
qint64 contentLength () const
 
QString contentType () const
 
QString contentTypeCharset () const
 
QVariant cookie (const QByteArray &name) const
 
QList< QNetworkCookie > cookies () const
 
bool hasBody () const
 
QString header (const QString &field) const
 
Headersheaders ()
 
bool isSequential () const override
 
QUrl location () const
 
void redirect (const QUrl &url, quint16 status=Found)
 
void redirect (const QString &url, quint16 status=Found)
 
int removeCookies (const QByteArray &name)
 
void setBody (QIODevice *body)
 
void setBody (const QByteArray &body)
 
void setBody (const QString &body)
 
void setContentEncoding (const QString &encoding)
 
void setContentLength (qint64 length)
 
void setContentType (const QString &type)
 
void setCookie (const QNetworkCookie &cookie)
 
void setCookies (const QList< QNetworkCookie > &cookies)
 
void setHeader (const QString &field, const QString &value)
 
void setJsonBody (const QJsonDocument &documment)
 
void setStatus (quint16 status)
 
qint64 size () const override
 
quint16 status () const
 

Protected Member Functions

 Response (Context *c, Engine *engine, const Headers &defaultHeaders)
 
virtual qint64 readData (char *data, qint64 maxlen) override
 
virtual qint64 writeData (const char *data, qint64 len) override
 

Protected Attributes

ResponsePrivate * d_ptr
 

Friends

class Application
 
class ContextPrivate
 
class Engine
 

Detailed Description

Definition at line 35 of file response.h.

Member Function Documentation

QByteArray& Cutelyst::Response::body ( )

This function returns a reference to a QByteArray which implicity sets the body device to a QBuffer, even if one was already set.

QIODevice* Cutelyst::Response::bodyDevice ( ) const

Returns the body IO device (if any) of this response.

QString Cutelyst::Response::contentEncoding ( ) const
qint64 Cutelyst::Response::contentLength ( ) const
QString Cutelyst::Response::contentType ( ) const
QString Cutelyst::Response::contentTypeCharset ( ) const
QVariant Cutelyst::Response::cookie ( const QByteArray &  name) const

Returns the first QNetworkCookie matching the name or a null QVariant if not found

QList<QNetworkCookie> Cutelyst::Response::cookies ( ) const

Returns a list of all cookies set

bool Cutelyst::Response::hasBody ( ) const

Returns true if a body device has been defined as QByteArray or QIODevice or write() was called and it's on chunked mode

QString Cutelyst::Response::header ( const QString &  field) const

Shortcut headers().header()

Headers& Cutelyst::Response::headers ( )

Returns a reference to the response headers class

bool Cutelyst::Response::isSequential ( ) const
override

Writting to user-agent is always sequential

QUrl Cutelyst::Response::location ( ) const

Returns the HTTP location set by the redirect

void Cutelyst::Response::redirect ( const QUrl &  url,
quint16  status = Found 
)

Causes the response to redirect to the specified URL. The default status is 302. This is a convenience method that sets the Location header to the redirect destination, and then sets the response status. You will want to return false or c->detach() to interrupt the normal processing flow if you want the redirect to occur straight away.

Note
do not give a relative URL as $url, i.e: one that is not fully qualified ("http://...", etc.) or that starts with a slash "/path/here". While it may work, it is not guaranteed to do the right thing and is not a standard behaviour. You may opt to use uriFor() or uriForAction() instead.
void Cutelyst::Response::redirect ( const QString &  url,
quint16  status = Found 
)

Causes the response to redirect to the specified URL. The default status is 302. This is a convenience method that sets the Location header to the redirect destination, and then sets the response status. You will want to return false or c->detach() to interrupt the normal processing flow if you want the redirect to occur straight away.

Note
do not give a relative URL as $url, i.e: one that is not fully qualified ("http://...", etc.) or that starts with a slash "/path/here". While it may work, it is not guaranteed to do the right thing and is not a standard behaviour. You may opt to use uriFor() or uriForAction() instead.
int Cutelyst::Response::removeCookies ( const QByteArray &  name)

Removes all cookies that matches name, returning the number of cookies removed

void Cutelyst::Response::setBody ( QIODevice *  body)

Sets an IO device as the response body, the open mode must be at least QIODevice::ReadOnly. This function takes ownership of your device deleting after the request has completed

void Cutelyst::Response::setBody ( const QByteArray &  body)

Sets a QByteArray as the response body, content length will be automatically set to it's size.

void Cutelyst::Response::setBody ( const QString &  body)
inline

Sets a QString as the response body, the output will be UTF-8 and content length will be automatically set to it's size.

Definition at line 284 of file response.h.

void Cutelyst::Response::setContentEncoding ( const QString &  encoding)

Short for headers().setContentEncoding(encoding);

void Cutelyst::Response::setContentLength ( qint64  length)

Short for headers().setContentLength(length);

void Cutelyst::Response::setContentType ( const QString &  type)
inline

Short for headers().setContentType(type);

Definition at line 173 of file response.h.

void Cutelyst::Response::setCookie ( const QNetworkCookie &  cookie)

Defines a QNetworkCookie to be sent to the user-agent, if a previous cookie->name() was set it will be replaced

void Cutelyst::Response::setCookies ( const QList< QNetworkCookie > &  cookies)

Defines a list of QNetworkCookie to be sent to the user-agent, all previous matches to cookie->name() will be preserved.

void Cutelyst::Response::setHeader ( const QString &  field,
const QString &  value 
)
void Cutelyst::Response::setJsonBody ( const QJsonDocument &  documment)

Sets a QJsonDocument as the response body, using toJson(QJsonDocument::Compact) output and setting content-type to application/json.

void Cutelyst::Response::setStatus ( quint16  status)

Sets the response code status

quint16 Cutelyst::Response::status ( ) const

The current response code status

virtual qint64 Cutelyst::Response::writeData ( const char *  data,
qint64  len 
)
overrideprotectedvirtual

Writes data to the response body, this will flush all response headers first and will enter in chunked mode if Transfer-Encoding header is set to chunked or if no content length is set and status is not 1xx or 204 (NoContent) or 304 (NotModified)