summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/httpserver/CMakeLists.txt4
-rw-r--r--src/httpserver/qabstracthttpserver.cpp48
-rw-r--r--src/httpserver/qhttpserver.cpp34
-rw-r--r--src/httpserver/qhttpserverfutureresponse.cpp9
-rw-r--r--src/httpserver/qhttpserverrequest.cpp74
-rw-r--r--src/httpserver/qhttpserverresponder.cpp20
-rw-r--r--src/httpserver/qhttpserverresponse.cpp94
-rw-r--r--src/httpserver/qhttpserverrouter.cpp18
-rw-r--r--src/httpserver/qhttpserverrouterrule.cpp26
-rw-r--r--src/sslserver/qsslserver.cpp28
10 files changed, 324 insertions, 31 deletions
diff --git a/src/httpserver/CMakeLists.txt b/src/httpserver/CMakeLists.txt
index 7a79bb6..8e290d9 100644
--- a/src/httpserver/CMakeLists.txt
+++ b/src/httpserver/CMakeLists.txt
@@ -52,3 +52,7 @@ qt_internal_extend_target(HttpServer CONDITION TARGET Qt::Concurrent
PUBLIC_LIBRARIES
Qt::Concurrent
)
+
+qt_internal_add_docs(HttpServer
+ ../../doc/config/qthttpserver.qdocconf
+)
diff --git a/src/httpserver/qabstracthttpserver.cpp b/src/httpserver/qabstracthttpserver.cpp
index 1695ede..ae2e374 100644
--- a/src/httpserver/qabstracthttpserver.cpp
+++ b/src/httpserver/qabstracthttpserver.cpp
@@ -45,10 +45,16 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcHttpServer, "qt.httpserver")
+/*!
+ \internal
+*/
QAbstractHttpServerPrivate::QAbstractHttpServerPrivate()
{
}
+/*!
+ \internal
+*/
void QAbstractHttpServerPrivate::handleNewConnections()
{
Q_Q(QAbstractHttpServer);
@@ -72,6 +78,9 @@ void QAbstractHttpServerPrivate::handleNewConnections()
}
}
+/*!
+ \internal
+*/
void QAbstractHttpServerPrivate::handleReadyRead(QTcpSocket *socket,
QHttpServerRequest *request)
{
@@ -121,10 +130,26 @@ void QAbstractHttpServerPrivate::handleReadyRead(QTcpSocket *socket,
socket->deleteLater();
}
+/*!
+ \class QAbstractHttpServer
+ \inmodule QtHttpServer
+ \brief API to subclass to implement an HTTP server.
+
+ Subclass this class and override \c handleRequest() to create an HTTP
+ server. Use \c listen() or \c bind() to start listening to incoming
+ connections.
+*/
+
+/*!
+ Creates an instance of QAbstractHttpServer with the parent \a parent.
+*/
QAbstractHttpServer::QAbstractHttpServer(QObject *parent)
: QAbstractHttpServer(*new QAbstractHttpServerPrivate, parent)
{}
+/*!
+ \internal
+*/
QAbstractHttpServer::QAbstractHttpServer(QAbstractHttpServerPrivate &dd, QObject *parent)
: QObject(dd, parent)
{
@@ -233,7 +258,7 @@ QVector<QTcpServer *> QAbstractHttpServer::servers() const
#if defined(QT_WEBSOCKETS_LIB)
/*!
- \fn QAbstractHttpServer::newConnection
+ \fn QAbstractHttpServer::newWebSocketConnection()
This signal is emitted every time a new WebSocket connection is
available.
@@ -272,12 +297,33 @@ QWebSocket *QAbstractHttpServer::nextPendingWebSocketConnection()
}
#endif
+/*!
+ \internal
+*/
QHttpServerResponder QAbstractHttpServer::makeResponder(const QHttpServerRequest &request,
QTcpSocket *socket)
{
return QHttpServerResponder(request, socket);
}
+/*!
+ \fn QAbstractHttpServer::handleRequest(const QHttpServerRequest &request,
+ QTcpSocket *socket)
+ Overload this function to handle each incoming \a request from \a socket,
+ by examining the \a request and sending the appropriate response back to
+ \a socket. Returns \c true if the \a request was handled. Otherwise,
+ returns \c false. If returning \c false, the \c missingHandler() signal
+ will be emitted.
+*/
+
+/*!
+ \fn QAbstractHttpServer::missingHandler(const QHttpServerRequest &request, QTcpSocket *socket)
+
+ This signal is emitted whenever \c handleRequest() returns \c false.
+ The \a request and \a socket parameters are the same as \c handleRequest()
+ was called with.
+*/
+
#if QT_CONFIG(ssl)
void QAbstractHttpServer::sslSetup(const QSslCertificate &certificate,
const QSslKey &privateKey,
diff --git a/src/httpserver/qhttpserver.cpp b/src/httpserver/qhttpserver.cpp
index b971235..061476f 100644
--- a/src/httpserver/qhttpserver.cpp
+++ b/src/httpserver/qhttpserver.cpp
@@ -46,6 +46,7 @@ Q_LOGGING_CATEGORY(lcHS, "qt.httpserver");
/*!
\class QHttpServer
+ \inmodule QtHttpServer
\brief QHttpServer is a simplified API for QAbstractHttpServer and QHttpServerRouter.
\code
@@ -60,6 +61,9 @@ Q_LOGGING_CATEGORY(lcHS, "qt.httpserver");
\endcode
*/
+/*!
+ Creates an instance of QHttpServer with parent \a parent.
+*/
QHttpServer::QHttpServer(QObject *parent)
: QAbstractHttpServer(*new QHttpServerPrivate, parent)
{
@@ -70,16 +74,21 @@ QHttpServer::QHttpServer(QObject *parent)
});
}
-/*! \fn template<typename Rule = QHttpServerRouterRule, typename ... Args> bool route(Args && ... args)
+/*! \fn template<typename Rule = QHttpServerRouterRule, typename ... Args> bool QHttpServer::route(Args && ... args)
+
This function is just a wrapper to simplify the router API.
- This function takes variadic arguments. The last argument is \c a callback (ViewHandler).
- The remaining arguments are used to create a new \a Rule (the default is QHttpServerRouterRule).
- This is in turn added to the QHttpServerRouter.
+ This function takes variadic arguments \a args. The last argument is a
+ callback (\c{ViewHandler}). The remaining arguments are used to create a
+ new \c Rule (the default is QHttpServerRouterRule). This is in turn added
+ to the QHttpServerRouter. It returns \c true if a new rule is created,
+ otherwise it returns \c false.
- \c ViewHandler can only be a lambda. The lambda definition can take two optional special
- arguments: \c {const QHttpServerRequest&} and \c {QHttpServerResponder&&}.
- These special arguments must be the last in the parameter list.
+ \c ViewHandler can only be a lambda. The lambda definition can take two
+ optional special arguments: \c {const QHttpServerRequest&} and
+ \c {QHttpServerResponder&&}. These special arguments must be the last in
+ the parameter list, but in any order, and there can be none, one, or both
+ of them present.
Examples:
@@ -102,11 +111,13 @@ QHttpServer::QHttpServer(QObject *parent)
\sa QHttpServerRouter::addRule
*/
-/*! \fn template<typename ViewHandler> void afterRequest(ViewHandler &&viewHandler)
+/*! \fn template<typename ViewHandler> void QHttpServer::afterRequest(ViewHandler &&viewHandler)
Register a function to be run after each request.
- \c ViewHandler can only be a lambda. The lambda definition can take two
- arguments: \c {QHttpServerResponse &&} and \c {const QHttpServerRequest&} (optional).
+ The \a viewHandler argument can only be a lambda. The lambda definition
+ can take one or two optional arguments: \c {QHttpServerResponse &&} and
+ \c {const QHttpServerRequest &}. If both are given, they can be in either
+ order.
Examples:
@@ -152,6 +163,9 @@ QHttpServerRouter *QHttpServer::router()
return &d->router;
}
+/*!
+ \internal
+*/
void QHttpServer::afterRequestImpl(AfterRequestHandler &&afterRequestHandler)
{
Q_D(QHttpServer);
diff --git a/src/httpserver/qhttpserverfutureresponse.cpp b/src/httpserver/qhttpserverfutureresponse.cpp
index 1d94df4..57c9f2c 100644
--- a/src/httpserver/qhttpserverfutureresponse.cpp
+++ b/src/httpserver/qhttpserverfutureresponse.cpp
@@ -43,6 +43,7 @@ QT_BEGIN_NAMESPACE
/*!
\class QHttpServerFutureResponse
+ \inmodule QtHttpServer
\brief QHttpServerFutureResponse is a simplified API for asynchronous responses.
\code
@@ -61,6 +62,9 @@ QT_BEGIN_NAMESPACE
\endcode
*/
+/*!
+ \internal
+*/
struct QResponseWatcher : public QFutureWatcher<QHttpServerResponse>
{
Q_OBJECT
@@ -74,6 +78,9 @@ public:
QHttpServerResponder responder;
};
+/*!
+ \internal
+*/
class QHttpServerFutureResponsePrivate : public QHttpServerResponsePrivate
{
public:
@@ -87,7 +94,7 @@ public:
};
/*!
- Constructs a new QHttpServerFutureResponse with the \a future response.
+ Constructs a new QHttpServerFutureResponse with the \a futureResp response.
*/
QHttpServerFutureResponse::QHttpServerFutureResponse(const QFuture<QHttpServerResponse> &futureResp)
: QHttpServerFutureResponse(new QHttpServerFutureResponsePrivate{futureResp})
diff --git a/src/httpserver/qhttpserverrequest.cpp b/src/httpserver/qhttpserverrequest.cpp
index 4263c50..2e6ef62 100644
--- a/src/httpserver/qhttpserverrequest.cpp
+++ b/src/httpserver/qhttpserverrequest.cpp
@@ -56,6 +56,9 @@ Q_HTTPSERVER_EXPORT QDebug operator<<(QDebug debug, const QHttpServerRequest &re
#endif
+/*!
+ \internal
+*/
bool QHttpServerRequestPrivate::parseRequestLine(QByteArrayView line)
{
// Request-Line = Method SP Request-URI SP HTTP-Version CRLF
@@ -113,6 +116,9 @@ bool QHttpServerRequestPrivate::parseRequestLine(QByteArrayView line)
return true;
}
+/*!
+ \internal
+*/
qsizetype QHttpServerRequestPrivate::readRequestLine(QAbstractSocket *socket)
{
if (fragment.isEmpty()) {
@@ -159,6 +165,9 @@ qsizetype QHttpServerRequestPrivate::readRequestLine(QAbstractSocket *socket)
return bytes;
}
+/*!
+ \internal
+*/
qint64 QHttpServerRequestPrivate::contentLength() const
{
bool ok = false;
@@ -169,6 +178,9 @@ qint64 QHttpServerRequestPrivate::contentLength() const
return -1; // the header field is not set
}
+/*!
+ \internal
+*/
QByteArray QHttpServerRequestPrivate::headerField(const QByteArray &name,
const QByteArray &defaultValue) const
{
@@ -179,11 +191,17 @@ QByteArray QHttpServerRequestPrivate::headerField(const QByteArray &name,
return allValues.join(", ");
}
+/*!
+ \internal
+*/
QList<QByteArray> QHttpServerRequestPrivate::headerFieldValues(const QByteArray &name) const
{
return parser.headerFieldValues(name);
}
+/*!
+ \internal
+*/
qsizetype QHttpServerRequestPrivate::readHeader(QAbstractSocket *socket)
{
if (fragment.isEmpty()) {
@@ -265,12 +283,18 @@ qsizetype QHttpServerRequestPrivate::readHeader(QAbstractSocket *socket)
return bytes;
}
+/*!
+ \internal
+*/
QHttpServerRequestPrivate::QHttpServerRequestPrivate(const QHostAddress &remoteAddress)
: remoteAddress(remoteAddress)
{
clear();
}
+/*!
+ \internal
+*/
bool QHttpServerRequestPrivate::parse(QAbstractSocket *socket)
{
qsizetype read;
@@ -307,6 +331,9 @@ bool QHttpServerRequestPrivate::parse(QAbstractSocket *socket)
return read != -1;
}
+/*!
+ \internal
+*/
void QHttpServerRequestPrivate::clear()
{
parser.clear();
@@ -325,6 +352,9 @@ void QHttpServerRequestPrivate::clear()
// The body reading functions were mostly copied from QHttpNetworkReplyPrivate
+/*!
+ \internal
+*/
// note this function can only be used for non-chunked, non-compressed with
// known content length
qsizetype QHttpServerRequestPrivate::readBodyFast(QAbstractSocket *socket)
@@ -353,6 +383,9 @@ qsizetype QHttpServerRequestPrivate::readBodyFast(QAbstractSocket *socket)
return haveRead;
}
+/*!
+ \internal
+*/
qsizetype QHttpServerRequestPrivate::readRequestBodyRaw(QAbstractSocket *socket, qsizetype size)
{
// FIXME get rid of this function and just use readBodyFast and give it socket->bytesAvailable()
@@ -381,6 +414,9 @@ qsizetype QHttpServerRequestPrivate::readRequestBodyRaw(QAbstractSocket *socket,
return bytes;
}
+/*!
+ \internal
+*/
qsizetype QHttpServerRequestPrivate::readRequestBodyChunked(QAbstractSocket *socket)
{
qsizetype bytes = 0;
@@ -440,6 +476,9 @@ qsizetype QHttpServerRequestPrivate::readRequestBodyChunked(QAbstractSocket *soc
return bytes;
}
+/*!
+ \internal
+*/
qsizetype QHttpServerRequestPrivate::getChunkSize(QAbstractSocket *socket, qsizetype *chunkSize)
{
qsizetype bytes = 0;
@@ -479,33 +518,62 @@ qsizetype QHttpServerRequestPrivate::getChunkSize(QAbstractSocket *socket, qsize
return bytes;
}
+/*!
+ \class QHttpServerRequest
+ \inmodule QtHttpServer
+ \brief Encapsulates an HTTP request.
+
+ API for accessing the different parameters of an incoming request.
+*/
+
+/*!
+ \internal
+*/
QHttpServerRequest::QHttpServerRequest(const QHostAddress &remoteAddress) :
d(new QHttpServerRequestPrivate(remoteAddress))
{}
+/*!
+ Destroys a QHttpServerRequest
+*/
QHttpServerRequest::~QHttpServerRequest()
{}
+/*!
+ Returns the combined value of all headers with the named \a key.
+*/
QByteArray QHttpServerRequest::value(const QByteArray &key) const
{
return d->parser.combinedHeaderValue(key);
}
+/*!
+ Returns the URL the request asked for.
+*/
QUrl QHttpServerRequest::url() const
{
return d->url;
}
+/*!
+ Returns the query in the request.
+*/
QUrlQuery QHttpServerRequest::query() const
{
return QUrlQuery(d->url.query());
}
+/*!
+ Returns the method of the request.
+*/
QHttpServerRequest::Method QHttpServerRequest::method() const
{
return d->method;
}
+/*!
+ Returns all the request headers.
+*/
QVariantMap QHttpServerRequest::headers() const
{
QVariantMap ret;
@@ -514,11 +582,17 @@ QVariantMap QHttpServerRequest::headers() const
return ret;
}
+/*!
+ Returns the body of the request.
+*/
QByteArray QHttpServerRequest::body() const
{
return d->body;
}
+/*!
+ Returns the address of the origin host of the request.
+*/
QHostAddress QHttpServerRequest::remoteAddress() const
{
return d->remoteAddress;
diff --git a/src/httpserver/qhttpserverresponder.cpp b/src/httpserver/qhttpserverresponder.cpp
index 94fdad9..0db17dd 100644
--- a/src/httpserver/qhttpserverresponder.cpp
+++ b/src/httpserver/qhttpserverresponder.cpp
@@ -41,6 +41,20 @@
QT_BEGIN_NAMESPACE
+/*!
+ \class QHttpServerResponder
+ \inmodule QtHttpServer
+ \brief API for sending replies from an HTTP server.
+
+ 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. This class can be constructed by calling the \c protected
+ \c static function \c makeResponder() in the QAbstractHttpServer class.
+*/
+
+/*!
+ \internal
+*/
static const QLoggingCategory &lc()
{
static const QLoggingCategory category("qt.httpserver.response");
@@ -92,6 +106,9 @@ static const std::map<QHttpServerResponder::StatusCode, QByteArray> statusString
#undef XX
};
+/*!
+ \internal
+*/
template <qint64 BUFFERSIZE = 512>
struct IOChunkedTransfer
{
@@ -174,8 +191,7 @@ struct IOChunkedTransfer
};
/*!
- Constructs a QHttpServerResponder using the request \a request
- and the socket \a socket.
+ \internal
*/
QHttpServerResponder::QHttpServerResponder(const QHttpServerRequest &request,
QTcpSocket *socket) :
diff --git a/src/httpserver/qhttpserverresponse.cpp b/src/httpserver/qhttpserverresponse.cpp
index 0d4ba4b..b325d71 100644
--- a/src/httpserver/qhttpserverresponse.cpp
+++ b/src/httpserver/qhttpserverresponse.cpp
@@ -41,21 +41,46 @@
QT_BEGIN_NAMESPACE
+/*!
+ \class QHttpServerResponse
+ \inmodule QtHttpServer
+ \brief Encapsulates an HTTP response.
+
+ 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 \c static function \c 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.
+*/
+
+/*!
+ \internal
+*/
QHttpServerResponsePrivate::QHttpServerResponsePrivate(
QByteArray &&d, const QHttpServerResponse::StatusCode sc)
: data(std::move(d)),
statusCode(sc)
{ }
+/*!
+ \internal
+*/
QHttpServerResponsePrivate::QHttpServerResponsePrivate(const QHttpServerResponse::StatusCode sc)
: statusCode(sc)
{ }
+/*!
+ Move-constructs an instance of a QHttpServerResponse object from \a other.
+*/
QHttpServerResponse::QHttpServerResponse(QHttpServerResponse &&other) noexcept
: d_ptr(std::move(other.d_ptr))
{
}
+/*!
+ Move-assigns the values of \a other to this object.
+*/
QHttpServerResponse& QHttpServerResponse::operator=(QHttpServerResponse &&other) noexcept
{
if (this == &other)
@@ -65,6 +90,9 @@ QHttpServerResponse& QHttpServerResponse::operator=(QHttpServerResponse &&other)
return *this;
}
+/*!
+ Creates a QHttpServerResponse object with the status code \a statusCode.
+*/
QHttpServerResponse::QHttpServerResponse(
const QHttpServerResponse::StatusCode statusCode)
: QHttpServerResponse(QHttpServerLiterals::contentTypeXEmpty(),
@@ -73,21 +101,34 @@ QHttpServerResponse::QHttpServerResponse(
{
}
+/*!
+ Creates a QHttpServerResponse object from \a data.
+*/
QHttpServerResponse::QHttpServerResponse(const char *data)
: QHttpServerResponse(QByteArray::fromRawData(data, qstrlen(data)))
{
}
+/*!
+ Creates a QHttpServerResponse object from \a data.
+*/
QHttpServerResponse::QHttpServerResponse(const QString &data)
: QHttpServerResponse(data.toUtf8())
{
}
+/*!
+ Creates a QHttpServerResponse object from \a data.
+*/
QHttpServerResponse::QHttpServerResponse(const QByteArray &data)
: QHttpServerResponse(QMimeDatabase().mimeTypeForData(data).name().toLocal8Bit(), data)
{
}
+/*!
+ Move-constructs a QHttpServerResponse whose body will contain the given
+ \a data.
+*/
QHttpServerResponse::QHttpServerResponse(QByteArray &&data)
: QHttpServerResponse(
QMimeDatabase().mimeTypeForData(data).name().toLocal8Bit(),
@@ -95,18 +136,44 @@ QHttpServerResponse::QHttpServerResponse(QByteArray &&data)
{
}
+/*!
+ Creates a QHttpServerResponse object from \a data.
+*/
QHttpServerResponse::QHttpServerResponse(const QJsonObject &data)
: QHttpServerResponse(QHttpServerLiterals::contentTypeJson(),
QJsonDocument(data).toJson(QJsonDocument::Compact))
{
}
+/*!
+ Creates a QHttpServerResponse object from \a data.
+*/
QHttpServerResponse::QHttpServerResponse(const QJsonArray &data)
: QHttpServerResponse(QHttpServerLiterals::contentTypeJson(),
QJsonDocument(data).toJson(QJsonDocument::Compact))
{
}
+/*!
+ \fn QHttpServerResponse::QHttpServerResponse(const QByteArray &mimeType,
+ const QByteArray &data,
+ const StatusCode status)
+ \fn QHttpServerResponse::QHttpServerResponse(QByteArray &&mimeType,
+ const QByteArray &data,
+ const StatusCode status)
+ \fn QHttpServerResponse::QHttpServerResponse(const QByteArray &mimeType,
+ QByteArray &&data,
+ const StatusCode status)
+ \fn QHttpServerResponse::QHttpServerResponse(QByteArray &&mimeType,
+ QByteArray &&data,
+ const StatusCode status)
+
+ Creates a QHttpServer response.
+
+ The response will use the given \a status code and deliver the \a data as
+ its body, with a \c ContentType header describing it as being of MIME type
+ \a mimeType.
+*/
QHttpServerResponse::QHttpServerResponse(const QByteArray &mimeType,
const QByteArray &data,
const StatusCode status)
@@ -139,10 +206,19 @@ QHttpServerResponse::QHttpServerResponse(QByteArray &&mimeType,
setHeader(QHttpServerLiterals::contentTypeHeader(), std::move(mimeType));
}
+/*!
+ Destroys a QHttpServerResponse object.
+*/
QHttpServerResponse::~QHttpServerResponse()
{
}
+/*!
+ Returns a QHttpServerResponse from the content of the file \a 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.
+*/
QHttpServerResponse QHttpServerResponse::fromFile(const QString &fileName)
{
QFile file(fileName);
@@ -154,6 +230,9 @@ QHttpServerResponse QHttpServerResponse::fromFile(const QString &fileName)
return QHttpServerResponse(mimeType, data);
}
+/*!
+ \internal
+*/
QHttpServerResponse::QHttpServerResponse(QHttpServerResponsePrivate *d)
: d_ptr(d)
{
@@ -161,7 +240,7 @@ QHttpServerResponse::QHttpServerResponse(QHttpServerResponsePrivate *d)
}
/*!
- Returns response body.
+ Returns the response body.
*/
QByteArray QHttpServerResponse::data() const
{
@@ -169,6 +248,9 @@ QByteArray QHttpServerResponse::data() const
return d->data;
}
+/*!
+ Returns the status code.
+*/
QHttpServerResponse::StatusCode QHttpServerResponse::statusCode() const
{
Q_D(const QHttpServerResponse);
@@ -176,7 +258,7 @@ QHttpServerResponse::StatusCode QHttpServerResponse::statusCode() const
}
/*!
- Returns HTTP "Content-Type" header.
+ Returns the value of the HTTP "Content-Type" header.
\note Default value is "text/html"
*/
@@ -231,6 +313,10 @@ void QHttpServerResponse::addHeader(const QByteArray &name, const QByteArray &va
d->headers.emplace(name, value);
}
+/*!
+ Adds the HTTP headers in \a headers,
+ does not override any previously set headers.
+*/
void QHttpServerResponse::addHeaders(QHttpServerResponder::HeaderList headers)
{
for (auto &&header : headers)
@@ -305,7 +391,7 @@ void QHttpServerResponse::setHeaders(QHttpServerResponder::HeaderList headers)
}
/*!
- Returns true if the response contains an HTTP header with name \a name,
+ Returns true if the response contains an HTTP header with name \a header,
otherwise returns false.
*/
bool QHttpServerResponse::hasHeader(const QByteArray &header) const
@@ -332,7 +418,7 @@ bool QHttpServerResponse::hasHeader(const QByteArray &name,
}
/*!
- Returns values of the HTTP header with name \a name
+ Returns values of the HTTP header with name \a name.
*/
QVector<QByteArray> QHttpServerResponse::headers(const QByteArray &name) const
{
diff --git a/src/httpserver/qhttpserverrouter.cpp b/src/httpserver/qhttpserverrouter.cpp
index e28d5cf..202f0ff 100644
--- a/src/httpserver/qhttpserverrouter.cpp
+++ b/src/httpserver/qhttpserverrouter.cpp
@@ -42,6 +42,9 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcRouter, "qt.httpserver.router")
+/*!
+ \internal
+*/
static const QMap<int, QLatin1String> defaultConverters = {
{ QMetaType::Int, QLatin1String("[+-]?\\d+") },
{ QMetaType::Long, QLatin1String("[+-]?\\d+") },
@@ -67,6 +70,7 @@ static const QMap<int, QLatin1String> defaultConverters = {
/*!
\class QHttpServerRouter
\brief Provides functions to bind a URL to a \c ViewHandler.
+ \inmodule QtHttpServer
You can register \c ViewHandler as a callback for requests to a specific URL.
Variable parts in the route can be specified by the arguments in ViewHandler.
@@ -99,7 +103,8 @@ static const QMap<int, QLatin1String> defaultConverters = {
/*! \fn template <typename Type> bool QHttpServerRouter::addConverter(const QLatin1String &regexp)
- Adds a new converter for type \e Type matching regular expression \a regexp.
+ Adds a new converter for type \e Type matching regular expression \a regexp,
+ and returns \c true if this was successful, otherwise returns \c false.
Automatically try to register an implicit converter from QString to \e Type.
If there is already a converter of type \e Type, that converter's regexp
@@ -137,7 +142,7 @@ static const QMap<int, QLatin1String> defaultConverters = {
/*! \fn template <typename ViewHandler, typename ViewTraits = QHttpServerRouterViewTraits<ViewHandler>> bool QHttpServerRouter::addRule(QHttpServerRouterRule *rule)
- Adds a new \a rule.
+ Adds a new \a rule and returns \c true if this was successful.
Inside addRule, we determine ViewHandler arguments and generate a list of
their QMetaType::Type ids. Then we parse the URL and replace each \c <arg>
@@ -161,13 +166,14 @@ static const QMap<int, QLatin1String> defaultConverters = {
\note This function takes over ownership of \a rule.
*/
-/*! \fn template<typename ViewHandler, typename ViewTraits = QHttpServerRouterViewTraits<ViewHandler>> auto bindCaptured(ViewHandler &&handler, QRegularExpressionMatch &match) const -> typename ViewTraits::BindableType
+/*! \fn template<typename ViewHandler, typename ViewTraits = QHttpServerRouterViewTraits<ViewHandler>> typename ViewTraits::BindableType QHttpServerRouter::bindCaptured(ViewHandler &&handler, const QRegularExpressionMatch &match) const
Supplies the \a handler with arguments derived from a URL.
Returns the bound function that accepts whatever remaining arguments the handler may take,
supplying them to the handler after the URL-derived values.
- Each match of the regex applied to the URL (as a string) is converted to the type
- of the handler's parameter at its position, so that passing it works.
+ Each match of the regex applied to the URL (as a string) is converted to
+ the type of the handler's parameter at its position, so that it can be
+ passed as \a match.
\code
QHttpServerRouter router;
@@ -291,7 +297,7 @@ bool QHttpServerRouter::addRuleImpl(QHttpServerRouterRule *rule,
}
/*!
- Handles each new request for the HTTP server.
+ Handles each new \a request for the HTTP server using \a socket.
Iterates through the list of rules to find the first that matches,
then executes this rule, returning \c true. Returns \c false if no rule
diff --git a/src/httpserver/qhttpserverrouterrule.cpp b/src/httpserver/qhttpserverrouterrule.cpp
index a3c5fd9..634846b 100644
--- a/src/httpserver/qhttpserverrouterrule.cpp
+++ b/src/httpserver/qhttpserverrouterrule.cpp
@@ -44,6 +44,9 @@ Q_LOGGING_CATEGORY(lcRouterRule, "qt.httpserver.router.rule")
static const auto methodEnum = QMetaEnum::fromType<QHttpServerRequest::Method>();
+/*!
+ \internal
+*/
static QHttpServerRequest::Methods strToMethods(const char *strMethods)
{
QHttpServerRequest::Methods methods;
@@ -61,6 +64,7 @@ static QHttpServerRequest::Methods strToMethods(const char *strMethods)
/*!
\class QHttpServerRouterRule
\brief The QHttpServerRouterRule is the base class for QHttpServerRouter rules.
+ \inmodule QtHttpServer
Use QHttpServerRouterRule to specify expected request parameters:
@@ -115,7 +119,7 @@ static QHttpServerRequest::Methods strToMethods(const char *strMethods)
The rule accepts all HTTP methods by default.
- \sq QHttpServerRequest::Method
+ \sa QHttpServerRequest::Methods
*/
QHttpServerRouterRule::QHttpServerRouterRule(const QString &pathPattern,
RouterHandler &&routerHandler)
@@ -131,7 +135,7 @@ QHttpServerRouterRule::QHttpServerRouterRule(const QString &pathPattern,
The rule accepts any combinations of available HTTP methods.
- \sa QHttpServerRequest::Method
+ \sa QHttpServerRequest::Methods
*/
QHttpServerRouterRule::QHttpServerRouterRule(const QString &pathPattern,
const QHttpServerRequest::Methods methods,
@@ -149,8 +153,6 @@ QHttpServerRouterRule::QHttpServerRouterRule(const QString &pathPattern,
\note \a methods shall be joined with | as separator (not spaces or commas)
and that either the upper-case or the capitalised form may be used.
-
- \sa QMetaEnum::keysToValue
*/
QHttpServerRouterRule::QHttpServerRouterRule(const QString &pathPattern,
const char *methods,
@@ -177,7 +179,7 @@ QHttpServerRouterRule::~QHttpServerRouterRule()
}
/*!
- Returns true if the methods is valid
+ Returns \c true if the methods is valid
*/
bool QHttpServerRouterRule::hasValidMethods() const
{
@@ -186,7 +188,12 @@ bool QHttpServerRouterRule::hasValidMethods() const
}
/*!
- This function is called by QHttpServerRouter when a new request is received.
+ Executes this rule for the given \a request, if it matches.
+
+ This function is called by QHttpServerRouter when it receives a new
+ request. If the given \a request matches this rule, this function handles
+ the request by delivering a response to the given \a socket, then returns
+ \c true. Otherwise, it returns \c false.
*/
bool QHttpServerRouterRule::exec(const QHttpServerRequest &request,
QTcpSocket *socket) const
@@ -202,7 +209,12 @@ bool QHttpServerRouterRule::exec(const QHttpServerRequest &request,
}
/*!
- This virtual function is called by exec() to check if request matches the rule.
+ Determines whether a given \a request matches this rule.
+
+ This virtual function is called by exec() to check if \a request matches
+ this rule. If a match is found, it is stored in the object pointed to by
+ \a match (which \e{must not} be \nullptr) and this function returns
+ \c true. Otherwise, it returns \c false.
*/
bool QHttpServerRouterRule::matches(const QHttpServerRequest &request,
QRegularExpressionMatch *match) const
diff --git a/src/sslserver/qsslserver.cpp b/src/sslserver/qsslserver.cpp
index 45c4826..12f0c68 100644
--- a/src/sslserver/qsslserver.cpp
+++ b/src/sslserver/qsslserver.cpp
@@ -35,11 +35,30 @@ QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcSS, "qt.sslserver");
+/*!
+ \class QSslServer
+ \inmodule QtHttpServer
+ \brief Subclass of QTcpServer to accept secure connections.
+
+ API for running a server with Transport Layer Security. Calling \c bind
+ on a QAbstractHttpServer with an instance of QSslServer turns it into an
+ HTTPS server.
+*/
+
+/*!
+ Creates a QSslServer object with \a parent as the parent object.
+*/
QSslServer::QSslServer(QObject *parent):
QTcpServer (parent), d(new QSslServerPrivate)
{
}
+/*!
+ Creates a QSslServer object.
+
+ Its parent object shall be \a parent and it shall use \a sslConfiguration as its
+ TLS configuration.
+*/
QSslServer::QSslServer(const QSslConfiguration &sslConfiguration,
QObject *parent):
QTcpServer (parent), d(new QSslServerPrivate)
@@ -47,8 +66,14 @@ QSslServer::QSslServer(const QSslConfiguration &sslConfiguration,
d->sslConfiguration = sslConfiguration;
}
+/*!
+ Destroys a QsslServer object.
+*/
QSslServer::~QSslServer() = default;
+/*!
+ Handle incoming connection with socket handle \a handle.
+*/
void QSslServer::incomingConnection(qintptr handle)
{
QSslSocket *socket = new QSslSocket(this);
@@ -70,6 +95,9 @@ void QSslServer::incomingConnection(qintptr handle)
addPendingConnection(socket);
}
+/*!
+ Sets the SSL configuration to \a sslConfiguration.
+*/
void QSslServer::setSslConfiguration(const QSslConfiguration &sslConfiguration)
{
d->sslConfiguration = sslConfiguration;