| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QNETWORKREQUEST_H |
| 5 | #define QNETWORKREQUEST_H |
| 6 | |
| 7 | #include <QtNetwork/qtnetworkglobal.h> |
| 8 | #include <QtNetwork/qhttpheaders.h> |
| 9 | #include <QtCore/QSharedDataPointer> |
| 10 | #include <QtCore/QString> |
| 11 | #include <QtCore/QUrl> |
| 12 | #include <QtCore/QVariant> |
| 13 | |
| 14 | #include <QtCore/q26numeric.h> |
| 15 | |
| 16 | QT_BEGIN_NAMESPACE |
| 17 | |
| 18 | class QSslConfiguration; |
| 19 | class QHttp2Configuration; |
| 20 | class QHttp1Configuration; |
| 21 | |
| 22 | class QNetworkRequestPrivate; |
| 23 | class Q_NETWORK_EXPORT QNetworkRequest |
| 24 | { |
| 25 | Q_GADGET |
| 26 | public: |
| 27 | enum { |
| 28 | , |
| 29 | , |
| 30 | , |
| 31 | , |
| 32 | , |
| 33 | , |
| 34 | , // added for QMultipartMessage |
| 35 | , |
| 36 | , |
| 37 | , |
| 38 | , |
| 39 | , |
| 40 | , |
| 41 | |
| 42 | }; |
| 43 | Q_ENUM(KnownHeaders) |
| 44 | |
| 45 | enum Attribute { |
| 46 | HttpStatusCodeAttribute, |
| 47 | HttpReasonPhraseAttribute, |
| 48 | RedirectionTargetAttribute, |
| 49 | ConnectionEncryptedAttribute, |
| 50 | CacheLoadControlAttribute, |
| 51 | CacheSaveControlAttribute, |
| 52 | SourceIsFromCacheAttribute, |
| 53 | DoNotBufferUploadDataAttribute, |
| 54 | HttpPipeliningAllowedAttribute, |
| 55 | HttpPipeliningWasUsedAttribute, |
| 56 | CustomVerbAttribute, |
| 57 | CookieLoadControlAttribute, |
| 58 | AuthenticationReuseAttribute, |
| 59 | CookieSaveControlAttribute, |
| 60 | MaximumDownloadBufferSizeAttribute, // internal |
| 61 | DownloadBufferAttribute, // internal |
| 62 | SynchronousRequestAttribute, // internal |
| 63 | BackgroundRequestAttribute, |
| 64 | EmitAllUploadProgressSignalsAttribute, |
| 65 | Http2AllowedAttribute, |
| 66 | Http2WasUsedAttribute, |
| 67 | OriginalContentLengthAttribute, |
| 68 | RedirectPolicyAttribute, |
| 69 | Http2DirectAttribute, |
| 70 | ResourceTypeAttribute, // internal |
| 71 | AutoDeleteReplyOnFinishAttribute, |
| 72 | ConnectionCacheExpiryTimeoutSecondsAttribute, |
| 73 | Http2CleartextAllowedAttribute, |
| 74 | UseCredentialsAttribute, |
| 75 | FullLocalServerNameAttribute, |
| 76 | |
| 77 | User = 1000, |
| 78 | UserMax = 32767 |
| 79 | }; |
| 80 | enum CacheLoadControl { |
| 81 | AlwaysNetwork, |
| 82 | PreferNetwork, |
| 83 | PreferCache, |
| 84 | AlwaysCache |
| 85 | }; |
| 86 | enum LoadControl { |
| 87 | Automatic = 0, |
| 88 | Manual |
| 89 | }; |
| 90 | |
| 91 | enum Priority { |
| 92 | HighPriority = 1, |
| 93 | NormalPriority = 3, |
| 94 | LowPriority = 5 |
| 95 | }; |
| 96 | |
| 97 | enum RedirectPolicy { |
| 98 | ManualRedirectPolicy, |
| 99 | NoLessSafeRedirectPolicy, |
| 100 | SameOriginRedirectPolicy, |
| 101 | UserVerifiedRedirectPolicy |
| 102 | }; |
| 103 | |
| 104 | enum TransferTimeoutConstant { |
| 105 | DefaultTransferTimeoutConstant = 30000 |
| 106 | }; |
| 107 | |
| 108 | static constexpr auto DefaultTransferTimeout = |
| 109 | std::chrono::milliseconds(DefaultTransferTimeoutConstant); |
| 110 | |
| 111 | QNetworkRequest(); |
| 112 | explicit QNetworkRequest(const QUrl &url); |
| 113 | QNetworkRequest(const QNetworkRequest &other); |
| 114 | ~QNetworkRequest(); |
| 115 | QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; } |
| 116 | QNetworkRequest &operator=(const QNetworkRequest &other); |
| 117 | |
| 118 | void swap(QNetworkRequest &other) noexcept { d.swap(other&: other.d); } |
| 119 | |
| 120 | bool operator==(const QNetworkRequest &other) const; |
| 121 | inline bool operator!=(const QNetworkRequest &other) const |
| 122 | { return !operator==(other); } |
| 123 | |
| 124 | QUrl url() const; |
| 125 | void setUrl(const QUrl &url); |
| 126 | |
| 127 | QHttpHeaders () const; |
| 128 | void (const QHttpHeaders &); |
| 129 | void (QHttpHeaders &&); |
| 130 | |
| 131 | // "cooked" headers |
| 132 | QVariant (KnownHeaders ) const; |
| 133 | void (KnownHeaders , const QVariant &value); |
| 134 | |
| 135 | // raw headers: |
| 136 | #if QT_NETWORK_REMOVED_SINCE(6, 7) |
| 137 | bool hasRawHeader(const QByteArray &headerName) const; |
| 138 | #endif |
| 139 | bool (QAnyStringView ) const; |
| 140 | QList<QByteArray> () const; |
| 141 | #if QT_NETWORK_REMOVED_SINCE(6, 7) |
| 142 | QByteArray rawHeader(const QByteArray &headerName) const; |
| 143 | #endif |
| 144 | QByteArray (QAnyStringView ) const; |
| 145 | void (const QByteArray &, const QByteArray &value); |
| 146 | |
| 147 | // attributes |
| 148 | QVariant attribute(Attribute code, const QVariant &defaultValue = QVariant()) const; |
| 149 | void setAttribute(Attribute code, const QVariant &value); |
| 150 | |
| 151 | #ifndef QT_NO_SSL |
| 152 | QSslConfiguration sslConfiguration() const; |
| 153 | void setSslConfiguration(const QSslConfiguration &configuration); |
| 154 | #endif |
| 155 | |
| 156 | void setOriginatingObject(QObject *object); |
| 157 | QObject *originatingObject() const; |
| 158 | |
| 159 | Priority priority() const; |
| 160 | void setPriority(Priority priority); |
| 161 | |
| 162 | // HTTP redirect related |
| 163 | int maximumRedirectsAllowed() const; |
| 164 | void setMaximumRedirectsAllowed(int maximumRedirectsAllowed); |
| 165 | |
| 166 | QString peerVerifyName() const; |
| 167 | void setPeerVerifyName(const QString &peerName); |
| 168 | #if QT_CONFIG(http) |
| 169 | QHttp1Configuration http1Configuration() const; |
| 170 | void setHttp1Configuration(const QHttp1Configuration &configuration); |
| 171 | |
| 172 | QHttp2Configuration http2Configuration() const; |
| 173 | void setHttp2Configuration(const QHttp2Configuration &configuration); |
| 174 | |
| 175 | qint64 decompressedSafetyCheckThreshold() const; |
| 176 | void setDecompressedSafetyCheckThreshold(qint64 threshold); |
| 177 | #endif // QT_CONFIG(http) |
| 178 | |
| 179 | #if QT_CONFIG(http) || defined (Q_OS_WASM) |
| 180 | QT_NETWORK_INLINE_SINCE(6, 8) |
| 181 | int transferTimeout() const; |
| 182 | QT_NETWORK_INLINE_SINCE(6, 8) |
| 183 | void setTransferTimeout(int timeout); |
| 184 | |
| 185 | std::chrono::milliseconds transferTimeoutAsDuration() const; |
| 186 | void setTransferTimeout(std::chrono::milliseconds duration = DefaultTransferTimeout); |
| 187 | #endif // QT_CONFIG(http) || defined (Q_OS_WASM) |
| 188 | private: |
| 189 | QSharedDataPointer<QNetworkRequestPrivate> d; |
| 190 | friend class QNetworkRequestPrivate; |
| 191 | }; |
| 192 | |
| 193 | Q_DECLARE_SHARED(QNetworkRequest) |
| 194 | |
| 195 | #if QT_NETWORK_INLINE_IMPL_SINCE(6, 8) |
| 196 | #if QT_CONFIG(http) || defined (Q_OS_WASM) |
| 197 | int QNetworkRequest::transferTimeout() const |
| 198 | { |
| 199 | return q26::saturate_cast<int>(x: transferTimeoutAsDuration().count()); |
| 200 | } |
| 201 | |
| 202 | void QNetworkRequest::setTransferTimeout(int timeout) |
| 203 | { |
| 204 | setTransferTimeout(std::chrono::milliseconds(timeout)); |
| 205 | } |
| 206 | #endif // QT_CONFIG(http) || defined (Q_OS_WASM) |
| 207 | #endif // INLINE_SINCE 6.8 |
| 208 | |
| 209 | QT_END_NAMESPACE |
| 210 | |
| 211 | QT_DECL_METATYPE_EXTERN(QNetworkRequest, Q_NETWORK_EXPORT) |
| 212 | QT_DECL_METATYPE_EXTERN_TAGGED(QNetworkRequest::RedirectPolicy, |
| 213 | QNetworkRequest__RedirectPolicy, Q_NETWORK_EXPORT) |
| 214 | |
| 215 | #endif |
| 216 | |