| 1 | // Copyright (C) 2019 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | // Qt-Security score:significant reason:default |
| 4 | |
| 5 | #ifndef QHTTPSERVERREQUEST_H |
| 6 | #define QHTTPSERVERREQUEST_H |
| 7 | |
| 8 | #include <QtHttpServer/qthttpserverglobal.h> |
| 9 | |
| 10 | #include <QtCore/qglobal.h> |
| 11 | #include <QtCore/qurl.h> |
| 12 | #include <QtCore/qurlquery.h> |
| 13 | #include <QtNetwork/qhostaddress.h> |
| 14 | #if QT_CONFIG(ssl) |
| 15 | #include <QtNetwork/qsslconfiguration.h> |
| 16 | #endif |
| 17 | |
| 18 | #include <memory> |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | class QRegularExpression; |
| 23 | class QString; |
| 24 | class ; |
| 25 | class QHttpServerParser; |
| 26 | |
| 27 | class QHttpServerRequestPrivate; |
| 28 | QT_DECLARE_QESDP_SPECIALIZATION_DTOR(QHttpServerRequestPrivate) |
| 29 | |
| 30 | class QHttpServerRequest final |
| 31 | { |
| 32 | friend class QHttpServerResponse; |
| 33 | friend class QHttpServerParser; |
| 34 | friend class QHttpServerStream; |
| 35 | friend class QHttpServerHttp1ProtocolHandler; |
| 36 | friend class QHttpServerHttp2ProtocolHandler; |
| 37 | |
| 38 | Q_GADGET_EXPORT(Q_HTTPSERVER_EXPORT) |
| 39 | |
| 40 | public: |
| 41 | Q_HTTPSERVER_EXPORT QHttpServerRequest(); |
| 42 | Q_HTTPSERVER_EXPORT QHttpServerRequest(const QHttpServerRequest &other); |
| 43 | Q_HTTPSERVER_EXPORT QHttpServerRequest &operator=(const QHttpServerRequest &other); |
| 44 | QHttpServerRequest(QHttpServerRequest &&other) noexcept = default; |
| 45 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QHttpServerRequest) |
| 46 | Q_HTTPSERVER_EXPORT ~QHttpServerRequest(); |
| 47 | void swap(QHttpServerRequest &other) noexcept { d.swap(other&: other.d); } |
| 48 | |
| 49 | enum class Method |
| 50 | { |
| 51 | Unknown = 0x0000, |
| 52 | Get = 0x0001, |
| 53 | Put = 0x0002, |
| 54 | Delete = 0x0004, |
| 55 | Post = 0x0008, |
| 56 | Head = 0x0010, |
| 57 | Options = 0x0020, |
| 58 | Patch = 0x0040, |
| 59 | Connect = 0x0080, |
| 60 | Trace = 0x0100, |
| 61 | |
| 62 | AnyKnown = Get | Put | Delete | Post | Head | Options | Patch | Connect | Trace, |
| 63 | }; |
| 64 | Q_ENUM(Method) |
| 65 | Q_DECLARE_FLAGS(Methods, Method) |
| 66 | Q_FLAG(Methods) |
| 67 | |
| 68 | Q_HTTPSERVER_EXPORT QByteArray value(const QByteArray &key) const; |
| 69 | Q_HTTPSERVER_EXPORT QUrl url() const; |
| 70 | Q_HTTPSERVER_EXPORT QUrlQuery query() const; |
| 71 | Q_HTTPSERVER_EXPORT Method method() const; |
| 72 | Q_HTTPSERVER_EXPORT const QHttpHeaders &() const &; |
| 73 | Q_HTTPSERVER_EXPORT QHttpHeaders () &&; |
| 74 | Q_HTTPSERVER_EXPORT QByteArray body() const; |
| 75 | Q_HTTPSERVER_EXPORT QHostAddress remoteAddress() const; |
| 76 | Q_HTTPSERVER_EXPORT quint16 remotePort() const; |
| 77 | Q_HTTPSERVER_EXPORT QHostAddress localAddress() const; |
| 78 | Q_HTTPSERVER_EXPORT quint16 localPort() const; |
| 79 | #if QT_CONFIG(ssl) |
| 80 | Q_HTTPSERVER_EXPORT QSslConfiguration sslConfiguration() const; |
| 81 | #endif |
| 82 | |
| 83 | private: |
| 84 | #if !defined(QT_NO_DEBUG_STREAM) |
| 85 | friend Q_HTTPSERVER_EXPORT QDebug operator<<(QDebug debug, const QHttpServerRequest &request); |
| 86 | #endif |
| 87 | |
| 88 | Q_HTTPSERVER_EXPORT static QHttpServerRequest create(const QHttpServerParser &parser); |
| 89 | #if QT_CONFIG(ssl) |
| 90 | Q_HTTPSERVER_EXPORT static QHttpServerRequest create(const QHttpServerParser &parser, |
| 91 | const QSslConfiguration &configuration); |
| 92 | #endif |
| 93 | |
| 94 | Q_HTTPSERVER_EXPORT explicit QHttpServerRequest(const QHostAddress &remoteAddress, |
| 95 | quint16 remotePort, |
| 96 | const QHostAddress &localAddress, |
| 97 | quint16 localPort); |
| 98 | #if QT_CONFIG(ssl) |
| 99 | Q_HTTPSERVER_EXPORT explicit QHttpServerRequest(const QHostAddress &remoteAddress, |
| 100 | quint16 remotePort, |
| 101 | const QHostAddress &localAddress, |
| 102 | quint16 localPort, |
| 103 | const QSslConfiguration &sslConfiguration); |
| 104 | #endif |
| 105 | |
| 106 | QExplicitlySharedDataPointer<QHttpServerRequestPrivate> d; |
| 107 | }; |
| 108 | |
| 109 | Q_DECLARE_SHARED(QHttpServerRequest) |
| 110 | |
| 111 | Q_DECLARE_OPERATORS_FOR_FLAGS(QHttpServerRequest::Methods) |
| 112 | |
| 113 | QT_END_NAMESPACE |
| 114 | |
| 115 | #endif // QHTTPSERVERREQUEST_H |
| 116 | |