6.0.0-rc4Source

QHttpServerRequest Class

The QHttpServerRequest class holds a request that a QAbstractHttpServer received. More…

Header#include <QHttpServerRequest>
CMaketarget_link_libraries(app PRIVATE Nt::HttpServer)
ModuleNt HTTP Server C++ Classes
Since6.4

List of all members, including inherited members

Public Types

enumMethod
typedefMethods

Public Functions

QHttpServerRequest(const QHttpServerRequest &other)
QHttpServerRequest(QHttpServerRequest &&other)
QHttpServerRequest &operator=(const QHttpServerRequest &other)
QHttpServerRequest &operator=(QHttpServerRequest &&other)
~QHttpServerRequest()
QByteArrayvalue(const QByteArray &key) const
QUrlurl() const
QUrlQueryquery() const
Methodmethod() const
const QHttpHeaders &headers() const &
QHttpHeadersheaders() &&
QByteArraybody() const
QHostAddressremoteAddress() const
quint16remotePort() const
QHostAddresslocalAddress() const
quint16localPort() 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.

ConstantDescription
QHttpServerRequest::UnknownA method that is not one of the others, such as PROPFIND.
QHttpServerRequest::GetGET
QHttpServerRequest::PutPUT
QHttpServerRequest::DeleteDELETE
QHttpServerRequest::PostPOST
QHttpServerRequest::HeadHEAD. The server leaves the body out of the response.
QHttpServerRequest::OptionsOPTIONS
QHttpServerRequest::PatchPATCH
QHttpServerRequest::ConnectCONNECT
QHttpServerRequest::TraceTRACE
QHttpServerRequest::AnyKnownAll 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().