1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QABSTRACTHTTPSERVER_H
5#define QABSTRACTHTTPSERVER_H
6
7#include <QtCore/qobject.h>
8
9#include <QtHttpServer/qthttpserverglobal.h>
10
11#include <QtNetwork/qhostaddress.h>
12
13#if QT_CONFIG(ssl)
14#include <QtNetwork/qssl.h>
15#endif
16
17#if defined(QT_WEBSOCKETS_LIB)
18#include <QtWebSockets/qwebsocket.h>
19#endif // defined(QT_WEBSOCKETS_LIB)
20
21#include <memory>
22
23QT_BEGIN_NAMESPACE
24
25class QHttpServerRequest;
26class QHttpServerResponder;
27class QSslCertificate;
28class QSslConfiguration;
29class QSslKey;
30class QTcpServer;
31
32class QAbstractHttpServerPrivate;
33class Q_HTTPSERVER_EXPORT QAbstractHttpServer : public QObject
34{
35 Q_OBJECT
36 friend class QHttpServerStream;
37
38public:
39 explicit QAbstractHttpServer(QObject *parent = nullptr);
40 ~QAbstractHttpServer() override;
41
42 quint16 listen(const QHostAddress &address = QHostAddress::Any, quint16 port = 0);
43 QList<quint16> serverPorts();
44
45 void bind(QTcpServer *server = nullptr);
46 QList<QTcpServer *> servers() const;
47
48#if QT_CONFIG(ssl)
49 void sslSetup(const QSslCertificate &certificate, const QSslKey &privateKey,
50 QSsl::SslProtocol protocol = QSsl::SecureProtocols);
51 void sslSetup(const QSslConfiguration &sslConfiguration);
52#endif
53
54#if defined(QT_WEBSOCKETS_LIB)
55Q_SIGNALS:
56 void newWebSocketConnection();
57
58public:
59 bool hasPendingWebSocketConnections() const;
60 std::unique_ptr<QWebSocket> nextPendingWebSocketConnection();
61#endif // defined(QT_WEBSOCKETS_LIB)
62
63protected:
64 QAbstractHttpServer(QAbstractHttpServerPrivate &dd, QObject *parent = nullptr);
65
66 virtual bool handleRequest(const QHttpServerRequest &request,
67 QHttpServerResponder &responder) = 0;
68 virtual void missingHandler(const QHttpServerRequest &request,
69 QHttpServerResponder &&responder) = 0;
70
71private:
72 Q_DECLARE_PRIVATE(QAbstractHttpServer)
73};
74
75QT_END_NAMESPACE
76
77#endif // QABSTRACTHTTPSERVER_H
78

source code of qthttpserver/src/httpserver/qabstracthttpserver.h