QHttpServerResponder Class
API for sending replies from an HTTP server. More...
| Header: | #include <QHttpServerResponder> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS HttpServer)target_link_libraries(mytarget PRIVATE Qt6::HttpServer) |
| qmake: | QT += httpserver |
| Since: | Qt 6.4 |
Public Types
| enum class | StatusCode { Continue, SwitchingProtocols, Processing, Ok, Created, …, NetworkConnectTimeoutError } |
Public Functions
| QHttpServerResponder(QHttpServerResponder &&other) | |
(since 6.11) class Q_DECL_IMPORT | isResponseCanceled() const |
(since 6.5) class Q_DECL_IMPORT | sendResponse(const QHttpServerResponse &response) |
(since 6.8) void | swap(QHttpServerResponder &other) |
| class Q_DECL_IMPORT | write(QHttpServerResponder::StatusCode status = StatusCode::Ok) |
| class Q_DECL_IMPORT | write(const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
| class Q_DECL_IMPORT | write(const int &document, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
| class Q_DECL_IMPORT | write(const int &data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
| class Q_DECL_IMPORT | write(const int &data, const int &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
| class Q_DECL_IMPORT | write(int *data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
| class Q_DECL_IMPORT | write(int *data, const int &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
(since 6.8) class Q_DECL_IMPORT | writeBeginChunked(const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
(since 6.8) class Q_DECL_IMPORT | writeBeginChunked(const int &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
(since 6.8) class Q_DECL_IMPORT | writeBeginChunked(const QHttpHeaders &headers, int trailers, QHttpServerResponder::StatusCode status = StatusCode::Ok) |
(since 6.8) class Q_DECL_IMPORT | writeChunk(const int &data) |
(since 6.8) class Q_DECL_IMPORT | writeEndChunked(const int &data) |
(since 6.8) class Q_DECL_IMPORT | writeEndChunked(const int &data, const QHttpHeaders &trailers) |
Detailed Description
Provides functions for writing back to an HTTP client with overloads for serializing JSON objects. It also has support for writing HTTP headers and status code.
Member Type Documentation
enum class QHttpServerResponder::StatusCode
HTTP status codes
| Constant | Value |
|---|---|
QHttpServerResponder::StatusCode::Continue | 100 |
QHttpServerResponder::StatusCode::SwitchingProtocols | 101 |
QHttpServerResponder::StatusCode::Processing | 102 |
QHttpServerResponder::StatusCode::Ok | 200 |
QHttpServerResponder::StatusCode::Created | 201 |
QHttpServerResponder::StatusCode::Accepted | 202 |
QHttpServerResponder::StatusCode::NonAuthoritativeInformation | 203 |
QHttpServerResponder::StatusCode::NoContent | 204 |
QHttpServerResponder::StatusCode::ResetContent | 205 |
QHttpServerResponder::StatusCode::PartialContent | 206 |
QHttpServerResponder::StatusCode::MultiStatus | 207 |
QHttpServerResponder::StatusCode::AlreadyReported | 208 |
QHttpServerResponder::StatusCode::IMUsed | 226 |
QHttpServerResponder::StatusCode::MultipleChoices | 300 |
QHttpServerResponder::StatusCode::MovedPermanently | 301 |
QHttpServerResponder::StatusCode::Found | 302 |
QHttpServerResponder::StatusCode::SeeOther | 303 |
QHttpServerResponder::StatusCode::NotModified | 304 |
QHttpServerResponder::StatusCode::UseProxy | 305 |
QHttpServerResponder::StatusCode::TemporaryRedirect | 307 |
QHttpServerResponder::StatusCode::PermanentRedirect | 308 |
QHttpServerResponder::StatusCode::BadRequest | 400 |
QHttpServerResponder::StatusCode::Unauthorized | 401 |
QHttpServerResponder::StatusCode::PaymentRequired | 402 |
QHttpServerResponder::StatusCode::Forbidden | 403 |
QHttpServerResponder::StatusCode::NotFound | 404 |
QHttpServerResponder::StatusCode::MethodNotAllowed | 405 |
QHttpServerResponder::StatusCode::NotAcceptable | 406 |
QHttpServerResponder::StatusCode::ProxyAuthenticationRequired | 407 |
QHttpServerResponder::StatusCode::RequestTimeout | 408 |
QHttpServerResponder::StatusCode::Conflict | 409 |
QHttpServerResponder::StatusCode::Gone | 410 |
QHttpServerResponder::StatusCode::LengthRequired | 411 |
QHttpServerResponder::StatusCode::PreconditionFailed | 412 |
QHttpServerResponder::StatusCode::PayloadTooLarge | 413 |
QHttpServerResponder::StatusCode::UriTooLong | 414 |
QHttpServerResponder::StatusCode::UnsupportedMediaType | 415 |
QHttpServerResponder::StatusCode::RequestRangeNotSatisfiable | 416 |
QHttpServerResponder::StatusCode::ExpectationFailed | 417 |
QHttpServerResponder::StatusCode::ImATeapot | 418 |
QHttpServerResponder::StatusCode::MisdirectedRequest | 421 |
QHttpServerResponder::StatusCode::UnprocessableEntity | 422 |
QHttpServerResponder::StatusCode::Locked | 423 |
QHttpServerResponder::StatusCode::FailedDependency | 424 |
QHttpServerResponder::StatusCode::UpgradeRequired | 426 |
QHttpServerResponder::StatusCode::PreconditionRequired | 428 |
QHttpServerResponder::StatusCode::TooManyRequests | 429 |
QHttpServerResponder::StatusCode::RequestHeaderFieldsTooLarge | 431 |
QHttpServerResponder::StatusCode::UnavailableForLegalReasons | 451 |
QHttpServerResponder::StatusCode::InternalServerError | 500 |
QHttpServerResponder::StatusCode::NotImplemented | 501 |
QHttpServerResponder::StatusCode::BadGateway | 502 |
QHttpServerResponder::StatusCode::ServiceUnavailable | 503 |
QHttpServerResponder::StatusCode::GatewayTimeout | 504 |
QHttpServerResponder::StatusCode::HttpVersionNotSupported | 505 |
QHttpServerResponder::StatusCode::VariantAlsoNegotiates | 506 |
QHttpServerResponder::StatusCode::InsufficientStorage | 507 |
QHttpServerResponder::StatusCode::LoopDetected | 508 |
QHttpServerResponder::StatusCode::NotExtended | 510 |
QHttpServerResponder::StatusCode::NetworkAuthenticationRequired | 511 |
QHttpServerResponder::StatusCode::NetworkConnectTimeoutError | 599 |
Member Function Documentation
[default] QHttpServerResponder::QHttpServerResponder(QHttpServerResponder &&other)
Move-constructs a QHttpServerResponder instance, making it point at the same object that other was pointing to.
[since 6.11] class Q_DECL_IMPORT QHttpServerResponder::isResponseCanceled() const
Returns true if the client has canceled the response. Used to make it possible to exit early in handler when the response is canceled.
This function was introduced in Qt 6.11.
[since 6.5] class Q_DECL_IMPORT QHttpServerResponder::sendResponse(const QHttpServerResponse &response)
Sends a HTTP response to the client.
This function was introduced in Qt 6.5.
[noexcept, since 6.8] void QHttpServerResponder::swap(QHttpServerResponder &other)
Swaps QHttpServerResponder other with this QHttpServerResponder. This operation is very fast and never fails.
This function was introduced in Qt 6.8.
class Q_DECL_IMPORT QHttpServerResponder::write(QHttpServerResponder::StatusCode status = StatusCode::Ok)
Answers a request with an HTTP status code status.
Note: This function sets HTTP Content-Type header as "application/x-empty".
class Q_DECL_IMPORT QHttpServerResponder::write(const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Answers a request with an HTTP status code status and HTTP Headers headers.
class Q_DECL_IMPORT QHttpServerResponder::write(const int &document, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Answers a request with an HTTP status code status, and JSON document document.
Note: This function sets HTTP Content-Type header as "application/json".
class Q_DECL_IMPORT QHttpServerResponder::write(const int &data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Answers a request with an HTTP status code status, HTTP Headers headers and a body data.
Note: This function sets HTTP Content-Length header.
class Q_DECL_IMPORT QHttpServerResponder::write(const int &data, const int &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Answers a request with an HTTP status code status, a MIME type mimeType and a body data.
class Q_DECL_IMPORT QHttpServerResponder::write(int *data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Answers a request with an HTTP status code status and HTTP headers headers. The I/O device data provides the body of the response. If data is sequential, the body of the message is sent in chunks: otherwise, the function assumes all the content is available and sends it all at once but the read is done in chunks.
Note: This function takes the ownership of data.
class Q_DECL_IMPORT QHttpServerResponder::write(int *data, const int &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Answers a request with an HTTP status code status and a MIME type mimeType. The I/O device data provides the body of the response. If data is sequential, the body of the message is sent in chunks: otherwise, the function assumes all the content is available and sends it all at once but the read is done in chunks.
Note: This function takes the ownership of data.
[since 6.8] class Q_DECL_IMPORT QHttpServerResponder::writeBeginChunked(const QHttpHeaders &headers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Start sending chunks of data with headers and and the status code status. This call must be followed up with an arbitrary number of repeated writeChunk calls and and a single call to writeEndChunked.
This function was introduced in Qt 6.8.
See also writeChunk and writeEndChunked.
[since 6.8] class Q_DECL_IMPORT QHttpServerResponder::writeBeginChunked(const int &mimeType, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Start sending chunks of data with the mime type mimeType and and the given status code status. This call must be followed up with an arbitrary number of repeated writeChunk calls and and a single call to writeEndChunked.
This function was introduced in Qt 6.8.
See also writeChunk and writeEndChunked.
[since 6.8] class Q_DECL_IMPORT QHttpServerResponder::writeBeginChunked(const QHttpHeaders &headers, int trailers, QHttpServerResponder::StatusCode status = StatusCode::Ok)
Start sending chunks of data with headers and and the given status code status. This call must be followed up with an arbitrary number of repeated writeChunk calls and and a single call to writeEndChunked with the same trailers given in trailers.
This function was introduced in Qt 6.8.
See also writeChunk and writeEndChunked.
[since 6.8] class Q_DECL_IMPORT QHttpServerResponder::writeChunk(const int &data)
Write data back to the client. To be called when data is available to write. This can be called multiple times, but before calling this writeBeginChunked must called, and afterwards writeEndChunked must be called.
This function was introduced in Qt 6.8.
See also writeBeginChunked and writeEndChunked.
[since 6.8] class Q_DECL_IMPORT QHttpServerResponder::writeEndChunked(const int &data)
Write data back to the client. Must be preceded by a call to writeBeginChunked.
This function was introduced in Qt 6.8.
See also writeBeginChunked and writeChunk.
[since 6.8] class Q_DECL_IMPORT QHttpServerResponder::writeEndChunked(const int &data, const QHttpHeaders &trailers)
Write data back to the client with the trailers announced in writeBeginChunked.
This function was introduced in Qt 6.8.
See also writeBeginChunked and writeChunk.