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
Status: Technical Preview

Public Types

Public Functions

QHttpServerResponse(QHttpServerResponse::StatusCode statusCode)
QHttpServerResponse(QByteArray &&data, QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QByteArray &data, QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QJsonArray &data, QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QJsonObject &data, QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QString &data, QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse(const char *data, QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QByteArray &mimeType, QByteArray &&data, QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse(const QByteArray &mimeType, const QByteArray &data, QHttpServerResponse::StatusCode status = StatusCode::Ok)
QHttpServerResponse(QHttpServerResponse &&other)
~QHttpServerResponse()
QByteArray data() const
(since 6.8) QHttpHeaders headers() const
QByteArray mimeType() const
(since 6.8) void setHeaders(QHttpHeaders &&newHeaders)
(since 6.8) void setHeaders(const QHttpHeaders &newHeaders)
QHttpServerResponse::StatusCode statusCode() const
void swap(QHttpServerResponse &other)
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(const QByteArray &mimeType, QByteArray &&data, QHttpServerResponse::StatusCode status = StatusCode::Ok)

QHttpServerResponse::QHttpServerResponse(const QByteArray &mimeType, const QByteArray &data, QHttpServerResponse::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(QHttpServerResponse::StatusCode statusCode)

Creates a QHttpServerResponse object with the status code statusCode.

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

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

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

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

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

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

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

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

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

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

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

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

[noexcept] QHttpServerResponse::QHttpServerResponse(QHttpServerResponse &&other)

Move-constructs a new QHttpServerResponse from other.

[noexcept] QHttpServerResponse::~QHttpServerResponse()

Destroys a QHttpServerResponse object.

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.

[since 6.8] QHttpHeaders QHttpServerResponse::headers() const

Returns the currently set HTTP headers.

This function was introduced in Qt 6.8.

See also setHeaders().

QByteArray QHttpServerResponse::mimeType() const

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

Note: Default value is "text/html"

[since 6.8] void QHttpServerResponse::setHeaders(QHttpHeaders &&newHeaders)

Sets newHeaders as the HTTP headers, overriding any previously set headers.

This function was introduced in Qt 6.8.

See also headers().

[since 6.8] void QHttpServerResponse::setHeaders(const QHttpHeaders &newHeaders)

This is an overloaded function.

This function was introduced in Qt 6.8.

QHttpServerResponse::StatusCode QHttpServerResponse::statusCode() const

Returns the status code.

[noexcept] void QHttpServerResponse::swap(QHttpServerResponse &other)

Swaps this QHttpServerResponse with other. This operation is very fast and never fails.

[noexcept] QHttpServerResponse &QHttpServerResponse::operator=(QHttpServerResponse &&other)

Move-assigns other to this QHttpServerResponse instance.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.