QHttpServerRequest Class
The QHttpServerRequest class holds a request that a QAbstractHttpServer received. More…
| Header | #include <QHttpServerRequest> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::HttpServer) |
| Module | Nt HTTP Server C++ Classes |
| Since | 6.4 |
List of all members, including inherited members
Public Types
Public Functions
| QHttpServerRequest(const QHttpServerRequest &other) | |
| QHttpServerRequest(QHttpServerRequest &&other) | |
| QHttpServerRequest & | operator=(const QHttpServerRequest &other) |
| QHttpServerRequest & | operator=(QHttpServerRequest &&other) |
| ~QHttpServerRequest() | |
| QByteArray | value(const QByteArray &key) const |
| QUrl | url() const |
| QUrlQuery | query() const |
| Method | method() const |
| const QHttpHeaders & | headers() const & |
| QHttpHeaders | headers() && |
| QByteArray | body() const |
| QHostAddress | remoteAddress() const |
| quint16 | remotePort() const |
| QHostAddress | localAddress() const |
| quint16 | localPort() const |
Detailed Description
The server reads the whole request, including its body, before it hands the request to a handler. A request holds the method, the URL, the header fields, the body and the addresses of both ends of the connection.
The URL is absolute: its scheme is http, or https on an encrypted connection, and its host and port come from the Host header, or from the local address when the request has none.
server.route("/echo", QHttpServerRequest::Method::Post, [](const QHttpServerRequest &request) {
return QHttpServerResponse("text/plain", request.body());
});
See also QHttpServer and QHttpServerResponder.
Differences from Qt
There is no sslConfiguration(). remoteAddress(), remotePort(), localAddress() and localPort() return a null address and 0 for requests that arrived on a QLocalServer.
Member Type Documentation
enum QHttpServerRequest::Method
The method of a request. The values can be combined into QHttpServerRequest::Methods to say which methods a route accepts.
| Constant | Description |
|---|---|
QHttpServerRequest::Unknown | A method that is not one of the others, such as PROPFIND. |
QHttpServerRequest::Get | GET |
QHttpServerRequest::Put | PUT |
QHttpServerRequest::Delete | DELETE |
QHttpServerRequest::Post | POST |
QHttpServerRequest::Head | HEAD. The server leaves the body out of the response. |
QHttpServerRequest::Options | OPTIONS |
QHttpServerRequest::Patch | PATCH |
QHttpServerRequest::Connect | CONNECT |
QHttpServerRequest::Trace | TRACE |
QHttpServerRequest::AnyKnown | All of the above except Unknown. |
typedef QHttpServerRequest::Methods
A QFlags of Method values.
Member Function Documentation
QHttpServerRequest::QHttpServerRequest(const QHttpServerRequest &other)
Constructs a copy of other.
QHttpServerRequest::QHttpServerRequest(QHttpServerRequest &&other)
Move-constructs a request from other.
QHttpServerRequest::~QHttpServerRequest()
Destroys the request.
QByteArray QHttpServerRequest::body() const
Returns the body of the request. A body sent with chunked transfer coding is returned decoded.
const QHttpHeaders & QHttpServerRequest::headers() const &
Returns the header fields of the request, in the order they arrived.
See also value().
QHttpHeaders QHttpServerRequest::headers() &&
This is an overloaded function.
Returns the header fields of the request, moved out of a temporary request.
QHostAddress QHttpServerRequest::localAddress() const
Returns the address of the server that received the request.
See also localPort() and remoteAddress().
quint16 QHttpServerRequest::localPort() const
Returns the port of the server that received the request.
See also localAddress().
Method QHttpServerRequest::method() const
Returns the method of the request.
QHttpServerRequest & QHttpServerRequest::operator=(const QHttpServerRequest &other)
Assigns other to this request and returns a reference to it.
QHttpServerRequest & QHttpServerRequest::operator=(QHttpServerRequest &&other)
This is an overloaded function.
Move-assigns other to this request and returns a reference to it.
QUrlQuery QHttpServerRequest::query() const
Returns the query of the URL.
See also url().
QHostAddress QHttpServerRequest::remoteAddress() const
Returns the address of the client.
See also remotePort() and localAddress().
quint16 QHttpServerRequest::remotePort() const
Returns the port of the client.
See also remoteAddress().
QUrl QHttpServerRequest::url() const
Returns the absolute URL of the request.
See also query().
QByteArray QHttpServerRequest::value(const QByteArray &key) const
Returns the value of the first header field named key, compared without regard to case, or an empty QByteArray if there is none.
See also headers().