QHttpServerResponse Class

Encapsulates an HTTP response. More...

Header: #include <QHttpServerResponse>
CMake: find_package(Qt6 REQUIRED COMPONENTS HttpServer)
target_link_libraries(mytarget PRIVATE Qt6::HttpServer)
qmake: QT += httpserver
Since: Qt 6.4

Public Types

Public Functions

QHttpServerResponse(const StatusCode statusCode)
QHttpServerResponse(const char *data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QString &data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QByteArray &data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(QByteArray &&data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QJsonObject &data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QJsonArray &data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QByteArray &mimeType, const QByteArray &data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(QByteArray &&mimeType, const QByteArray &data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QByteArray &mimeType, QByteArray &&data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(QByteArray &&mimeType, QByteArray &&data, const StatusCode status = StatusCode::Ok)
QHttpServerResponse(QHttpServerResponse &&other)
~QHttpServerResponse()
void addHeader(QByteArray &&name, QByteArray &&value)
void addHeader(QByteArray &&name, const QByteArray &value)
void addHeader(const QByteArray &name, QByteArray &&value)
void addHeader(const QByteArray &name, const QByteArray &value)
void addHeaders(const Container &headerList)
QByteArray data() const
QByteArray mimeType() const
StatusCode statusCode() const
QHttpServerResponse &operator=(QHttpServerResponse &&other)

Static Public Members

QHttpServerResponse fromFile(const QString &fileName)

Detailed Description

API for creating, reading and modifying a response from an HTTP server, and for writing its contents to a QHttpServerResponder. It has numerous constructors, and static function fromFile for constructing it from the contents of a file. There are functions for setting, getting, and removing headers, and for getting the data, status code and mime type.

Member Type Documentation

[alias] QHttpServerResponse::StatusCode

Type alias for QHttpServerResponder::StatusCode

Member Function Documentation

QHttpServerResponse::QHttpServerResponse(QByteArray &&mimeType, QByteArray &&data, const StatusCode status = StatusCode::Ok)

QHttpServerResponse::QHttpServerResponse(QByteArray &&mimeType, const QByteArray &data, const StatusCode status = StatusCode::Ok)

QHttpServerResponse::QHttpServerResponse(const QByteArray &mimeType, QByteArray &&data, const StatusCode status = StatusCode::Ok)

QHttpServerResponse::QHttpServerResponse(const QByteArray &mimeType, const QByteArray &data, const StatusCode status = StatusCode::Ok)

Creates a QHttpServer response.

The response will use the given status code and deliver the data as its body, with a ContentType header describing it as being of MIME type mimeType.

QHttpServerResponse::QHttpServerResponse(const StatusCode statusCode)

Creates a QHttpServerResponse object with the status code statusCode.

QHttpServerResponse::QHttpServerResponse(const char *data, const StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status.

QHttpServerResponse::QHttpServerResponse(const QString &data, const StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status.

[explicit] QHttpServerResponse::QHttpServerResponse(const QByteArray &data, const StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status.

[explicit] QHttpServerResponse::QHttpServerResponse(QByteArray &&data, const StatusCode status = StatusCode::Ok)

Move-constructs a QHttpServerResponse whose body will contain the given data with the status code status.

QHttpServerResponse::QHttpServerResponse(const QJsonObject &data, const StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status.

QHttpServerResponse::QHttpServerResponse(const QJsonArray &data, const StatusCode status = StatusCode::Ok)

Creates a QHttpServerResponse object from data with the status code status.

QHttpServerResponse::QHttpServerResponse(QHttpServerResponse &&other)

Move-constructs an instance of a QHttpServerResponse object from other.

QHttpServerResponse::~QHttpServerResponse()

Destroys a QHttpServerResponse object.

void QHttpServerResponse::addHeader(QByteArray &&name, QByteArray &&value)

Adds the HTTP header with name name and value value, does not override any previously set headers.

void QHttpServerResponse::addHeader(QByteArray &&name, const QByteArray &value)

Adds the HTTP header with name name and value value, does not override any previously set headers.

void QHttpServerResponse::addHeader(const QByteArray &name, QByteArray &&value)

Adds the HTTP header with name name and value value, does not override any previously set headers.

void QHttpServerResponse::addHeader(const QByteArray &name, const QByteArray &value)

Adds the HTTP header with name name and value value, does not override any previously set headers.

template <typename Container> void QHttpServerResponse::addHeaders(const Container &headerList)

Adds the HTTP headers in headerList, does not override any previously set headers.

Container must be a container that represents the header name and content as key-value pairs.

QByteArray QHttpServerResponse::data() const

Returns the response body.

[static] QHttpServerResponse QHttpServerResponse::fromFile(const QString &fileName)

Returns a QHttpServerResponse from the content of the file fileName.

It is the caller's responsibility to sanity-check the filename, and to have a well-defined policy for which files the server will request.

QByteArray QHttpServerResponse::mimeType() const

Returns the value of the HTTP "Content-Type" header.

Note: Default value is "text/html"

StatusCode QHttpServerResponse::statusCode() const

Returns the status code.

QHttpServerResponse &QHttpServerResponse::operator=(QHttpServerResponse &&other)

Move-assigns the values of other to this object.