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