/src/qt/qtbase/src/network/access/qhttpheaders.h
Line | Count | Source |
1 | | // Copyright (C) 2023 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 | | // Qt-Security score:significant reason:default |
4 | | |
5 | | #ifndef QHTTPHEADERS_H |
6 | | #define QHTTPHEADERS_H |
7 | | |
8 | | #include <QtNetwork/qtnetworkglobal.h> |
9 | | |
10 | | #include <QtCore/qdatetime.h> |
11 | | #include <QtCore/qmetaobject.h> |
12 | | #include <QtCore/qobjectdefs.h> |
13 | | #include <QtCore/qshareddata.h> |
14 | | #include <QtCore/qcontainerfwd.h> |
15 | | |
16 | | QT_BEGIN_NAMESPACE |
17 | | |
18 | | class QDebug; |
19 | | |
20 | | class QHttpHeadersPrivate; |
21 | | QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QHttpHeadersPrivate, Q_NETWORK_EXPORT) |
22 | | class QHttpHeaders |
23 | | { |
24 | | Q_GADGET_EXPORT(Q_NETWORK_EXPORT) |
25 | | public: |
26 | | enum class WellKnownHeader { |
27 | | // IANA Permanent status: |
28 | | AIM, |
29 | | Accept, |
30 | | AcceptAdditions, |
31 | | AcceptCH, |
32 | | AcceptDatetime, |
33 | | AcceptEncoding, |
34 | | AcceptFeatures, |
35 | | AcceptLanguage, |
36 | | AcceptPatch, |
37 | | AcceptPost, |
38 | | AcceptRanges, |
39 | | AcceptSignature, |
40 | | AccessControlAllowCredentials, |
41 | | AccessControlAllowHeaders, |
42 | | AccessControlAllowMethods, |
43 | | AccessControlAllowOrigin, |
44 | | AccessControlExposeHeaders, |
45 | | AccessControlMaxAge, |
46 | | AccessControlRequestHeaders, |
47 | | AccessControlRequestMethod, |
48 | | Age, |
49 | | Allow, |
50 | | ALPN, |
51 | | AltSvc, |
52 | | AltUsed, |
53 | | Alternates, |
54 | | ApplyToRedirectRef, |
55 | | AuthenticationControl, |
56 | | AuthenticationInfo, |
57 | | Authorization, |
58 | | CacheControl, |
59 | | CacheStatus, |
60 | | CalManagedID, |
61 | | CalDAVTimezones, |
62 | | CapsuleProtocol, |
63 | | CDNCacheControl, |
64 | | CDNLoop, |
65 | | CertNotAfter, |
66 | | CertNotBefore, |
67 | | ClearSiteData, |
68 | | ClientCert, |
69 | | ClientCertChain, |
70 | | Close, |
71 | | Connection, |
72 | | ContentDigest, |
73 | | ContentDisposition, |
74 | | ContentEncoding, |
75 | | ContentID, |
76 | | ContentLanguage, |
77 | | ContentLength, |
78 | | ContentLocation, |
79 | | ContentRange, |
80 | | ContentSecurityPolicy, |
81 | | ContentSecurityPolicyReportOnly, |
82 | | ContentType, |
83 | | Cookie, |
84 | | CrossOriginEmbedderPolicy, |
85 | | CrossOriginEmbedderPolicyReportOnly, |
86 | | CrossOriginOpenerPolicy, |
87 | | CrossOriginOpenerPolicyReportOnly, |
88 | | CrossOriginResourcePolicy, |
89 | | DASL, |
90 | | Date, |
91 | | DAV, |
92 | | DeltaBase, |
93 | | Depth, |
94 | | Destination, |
95 | | DifferentialID, |
96 | | DPoP, |
97 | | DPoPNonce, |
98 | | EarlyData, |
99 | | ETag, |
100 | | Expect, |
101 | | ExpectCT, |
102 | | Expires, |
103 | | Forwarded, |
104 | | From, |
105 | | Hobareg, |
106 | | Host, |
107 | | If, |
108 | | IfMatch, |
109 | | IfModifiedSince, |
110 | | IfNoneMatch, |
111 | | IfRange, |
112 | | IfScheduleTagMatch, |
113 | | IfUnmodifiedSince, |
114 | | IM, |
115 | | IncludeReferredTokenBindingID, |
116 | | KeepAlive, |
117 | | Label, |
118 | | LastEventID, |
119 | | LastModified, |
120 | | Link, |
121 | | Location, |
122 | | LockToken, |
123 | | MaxForwards, |
124 | | MementoDatetime, |
125 | | Meter, |
126 | | MIMEVersion, |
127 | | Negotiate, |
128 | | NEL, |
129 | | ODataEntityId, |
130 | | ODataIsolation, |
131 | | ODataMaxVersion, |
132 | | ODataVersion, |
133 | | OptionalWWWAuthenticate, |
134 | | OrderingType, |
135 | | Origin, |
136 | | OriginAgentCluster, |
137 | | OSCORE, |
138 | | OSLCCoreVersion, |
139 | | Overwrite, |
140 | | PingFrom, |
141 | | PingTo, |
142 | | Position, |
143 | | Prefer, |
144 | | PreferenceApplied, |
145 | | Priority, |
146 | | ProxyAuthenticate, |
147 | | ProxyAuthenticationInfo, |
148 | | ProxyAuthorization, |
149 | | ProxyStatus, |
150 | | PublicKeyPins, |
151 | | PublicKeyPinsReportOnly, |
152 | | Range, |
153 | | RedirectRef, |
154 | | Referer, |
155 | | Refresh, |
156 | | ReplayNonce, |
157 | | ReprDigest, |
158 | | RetryAfter, |
159 | | ScheduleReply, |
160 | | ScheduleTag, |
161 | | SecPurpose, |
162 | | SecTokenBinding, |
163 | | SecWebSocketAccept, |
164 | | SecWebSocketExtensions, |
165 | | SecWebSocketKey, |
166 | | SecWebSocketProtocol, |
167 | | SecWebSocketVersion, |
168 | | Server, |
169 | | ServerTiming, |
170 | | SetCookie, |
171 | | Signature, |
172 | | SignatureInput, |
173 | | SLUG, |
174 | | SoapAction, |
175 | | StatusURI, |
176 | | StrictTransportSecurity, |
177 | | Sunset, |
178 | | SurrogateCapability, |
179 | | SurrogateControl, |
180 | | TCN, |
181 | | TE, |
182 | | Timeout, |
183 | | Topic, |
184 | | Traceparent, |
185 | | Tracestate, |
186 | | Trailer, |
187 | | TransferEncoding, |
188 | | TTL, |
189 | | Upgrade, |
190 | | Urgency, |
191 | | UserAgent, |
192 | | VariantVary, |
193 | | Vary, |
194 | | Via, |
195 | | WantContentDigest, |
196 | | WantReprDigest, |
197 | | WWWAuthenticate, |
198 | | XContentTypeOptions, |
199 | | XFrameOptions, |
200 | | // IANA Deprecated status: |
201 | | AcceptCharset, |
202 | | CPEPInfo, |
203 | | Pragma, |
204 | | ProtocolInfo, |
205 | | ProtocolQuery, |
206 | | }; |
207 | 0 | Q_ENUM(WellKnownHeader) Unexecuted instantiation: qt_getEnumMetaObject(QHttpHeaders::WellKnownHeader) Unexecuted instantiation: qt_getEnumName(QHttpHeaders::WellKnownHeader) |
208 | 0 |
|
209 | 0 | Q_NETWORK_EXPORT QHttpHeaders() noexcept; |
210 | 0 | Q_NETWORK_EXPORT ~QHttpHeaders(); |
211 | 0 |
|
212 | 0 | Q_NETWORK_EXPORT QHttpHeaders(const QHttpHeaders &other); |
213 | 0 | QHttpHeaders(QHttpHeaders &&other) noexcept = default; |
214 | | Q_NETWORK_EXPORT QHttpHeaders &operator=(const QHttpHeaders &other); |
215 | 0 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QHttpHeaders) |
216 | 0 | void swap(QHttpHeaders &other) noexcept { d.swap(other.d); } |
217 | | |
218 | | Q_NETWORK_EXPORT bool append(QAnyStringView name, QAnyStringView value); |
219 | | Q_NETWORK_EXPORT bool append(WellKnownHeader name, QAnyStringView value); |
220 | | |
221 | | Q_NETWORK_EXPORT bool insert(qsizetype i, QAnyStringView name, QAnyStringView value); |
222 | | Q_NETWORK_EXPORT bool insert(qsizetype i, WellKnownHeader name, QAnyStringView value); |
223 | | |
224 | | Q_NETWORK_EXPORT bool replace(qsizetype i, QAnyStringView name, QAnyStringView newValue); |
225 | | Q_NETWORK_EXPORT bool replace(qsizetype i, WellKnownHeader name, QAnyStringView newValue); |
226 | | |
227 | | Q_NETWORK_EXPORT bool replaceOrAppend(QAnyStringView name, QAnyStringView newValue); |
228 | | Q_NETWORK_EXPORT bool replaceOrAppend(WellKnownHeader name, QAnyStringView newValue); |
229 | | |
230 | | Q_NETWORK_EXPORT bool contains(QAnyStringView name) const; |
231 | | Q_NETWORK_EXPORT bool contains(WellKnownHeader name) const; |
232 | | |
233 | | Q_NETWORK_EXPORT void clear(); |
234 | | Q_NETWORK_EXPORT void removeAll(QAnyStringView name); |
235 | | Q_NETWORK_EXPORT void removeAll(WellKnownHeader name); |
236 | | Q_NETWORK_EXPORT void removeAt(qsizetype i); |
237 | | |
238 | | Q_NETWORK_EXPORT QByteArrayView value(QAnyStringView name, QByteArrayView defaultValue = {}) const noexcept; |
239 | | Q_NETWORK_EXPORT QByteArrayView value(WellKnownHeader name, QByteArrayView defaultValue = {}) const noexcept; |
240 | | |
241 | | Q_NETWORK_EXPORT QList<QByteArray> values(QAnyStringView name) const; |
242 | | Q_NETWORK_EXPORT QList<QByteArray> values(WellKnownHeader name) const; |
243 | | |
244 | | Q_NETWORK_EXPORT QByteArrayView valueAt(qsizetype i) const noexcept; |
245 | | Q_NETWORK_EXPORT QLatin1StringView nameAt(qsizetype i) const noexcept; |
246 | | |
247 | | Q_NETWORK_EXPORT QByteArray combinedValue(QAnyStringView name) const; |
248 | | Q_NETWORK_EXPORT QByteArray combinedValue(WellKnownHeader name) const; |
249 | | |
250 | | Q_NETWORK_EXPORT std::optional<qint64> intValue(QAnyStringView name) const noexcept; |
251 | | Q_NETWORK_EXPORT std::optional<qint64> intValue(WellKnownHeader name) const noexcept; |
252 | | |
253 | | Q_NETWORK_EXPORT std::optional<QList<qint64>> intValues(QAnyStringView name) const; |
254 | | Q_NETWORK_EXPORT std::optional<QList<qint64>> intValues(WellKnownHeader name) const; |
255 | | |
256 | | Q_NETWORK_EXPORT std::optional<qint64> intValueAt(qsizetype i) const noexcept; |
257 | | |
258 | | Q_NETWORK_EXPORT std::optional<QDateTime> dateTimeValue(QAnyStringView name) const; |
259 | | Q_NETWORK_EXPORT std::optional<QDateTime> dateTimeValue(WellKnownHeader name) const; |
260 | | |
261 | | Q_NETWORK_EXPORT std::optional<QList<QDateTime>> dateTimeValues(QAnyStringView name) const; |
262 | | Q_NETWORK_EXPORT std::optional<QList<QDateTime>> dateTimeValues(WellKnownHeader name) const; |
263 | | |
264 | | Q_NETWORK_EXPORT std::optional<QDateTime> dateTimeValueAt(qsizetype i) const; |
265 | | |
266 | | Q_NETWORK_EXPORT void setDateTimeValue(QAnyStringView name, const QDateTime &dateTime); |
267 | | Q_NETWORK_EXPORT void setDateTimeValue(WellKnownHeader name, const QDateTime &dateTime); |
268 | | |
269 | | Q_NETWORK_EXPORT qsizetype size() const noexcept; |
270 | | Q_NETWORK_EXPORT void reserve(qsizetype size); |
271 | 0 | bool isEmpty() const noexcept { return size() == 0; } |
272 | | |
273 | | Q_NETWORK_EXPORT static QByteArrayView wellKnownHeaderName(WellKnownHeader name) noexcept; |
274 | | |
275 | | Q_NETWORK_EXPORT static QHttpHeaders |
276 | | fromListOfPairs(const QList<std::pair<QByteArray, QByteArray>> &headers); |
277 | | Q_NETWORK_EXPORT static QHttpHeaders |
278 | | fromMultiMap(const QMultiMap<QByteArray, QByteArray> &headers); |
279 | | Q_NETWORK_EXPORT static QHttpHeaders |
280 | | fromMultiHash(const QMultiHash<QByteArray, QByteArray> &headers); |
281 | | |
282 | | Q_NETWORK_EXPORT QList<std::pair<QByteArray, QByteArray>> toListOfPairs() const; |
283 | | Q_NETWORK_EXPORT QMultiMap<QByteArray, QByteArray> toMultiMap() const; |
284 | | Q_NETWORK_EXPORT QMultiHash<QByteArray, QByteArray> toMultiHash() const; |
285 | | |
286 | | private: |
287 | | #ifndef QT_NO_DEBUG_STREAM |
288 | | friend Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QHttpHeaders &headers); |
289 | | #endif |
290 | | Q_ALWAYS_INLINE void verify([[maybe_unused]] qsizetype pos = 0, |
291 | | [[maybe_unused]] qsizetype n = 1) const |
292 | 0 | { |
293 | 0 | Q_ASSERT(pos >= 0); |
294 | 0 | Q_ASSERT(pos <= size()); |
295 | 0 | Q_ASSERT(n >= 0); |
296 | 0 | Q_ASSERT(n <= size() - pos); |
297 | 0 | } |
298 | | QExplicitlySharedDataPointer<QHttpHeadersPrivate> d; |
299 | | }; |
300 | | |
301 | | Q_DECLARE_SHARED(QHttpHeaders) |
302 | | |
303 | | QT_END_NAMESPACE |
304 | | |
305 | | #endif // QHTTPHEADERS_H |