Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qhttpheaders.h
Go to the documentation of this file.
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
4#ifndef QHTTPHEADERS_H
5#define QHTTPHEADERS_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtCore/qmetaobject.h>
9#include <QtCore/qshareddata.h>
10#include <QtCore/qcontainerfwd.h>
11
13
14class QDebug;
15
19{
20 Q_GADGET_EXPORT(Q_NETWORK_EXPORT)
21public:
22 enum class WellKnownHeader {
23 // IANA Permanent status:
24 AIM,
25 Accept,
26 AcceptAdditions,
27 AcceptCH,
28 AcceptDatetime,
29 AcceptEncoding,
30 AcceptFeatures,
31 AcceptLanguage,
32 AcceptPatch,
33 AcceptPost,
34 AcceptRanges,
35 AcceptSignature,
36 AccessControlAllowCredentials,
37 AccessControlAllowHeaders,
38 AccessControlAllowMethods,
39 AccessControlAllowOrigin,
40 AccessControlExposeHeaders,
41 AccessControlMaxAge,
42 AccessControlRequestHeaders,
43 AccessControlRequestMethod,
44 Age,
45 Allow,
46 ALPN,
47 AltSvc,
48 AltUsed,
49 Alternates,
50 ApplyToRedirectRef,
51 AuthenticationControl,
52 AuthenticationInfo,
53 Authorization,
54 CacheControl,
55 CacheStatus,
56 CalManagedID,
57 CalDAVTimezones,
58 CapsuleProtocol,
59 CDNCacheControl,
60 CDNLoop,
61 CertNotAfter,
62 CertNotBefore,
63 ClearSiteData,
64 ClientCert,
65 ClientCertChain,
66 Close,
68 ContentDigest,
69 ContentDisposition,
70 ContentEncoding,
71 ContentID,
72 ContentLanguage,
73 ContentLength,
74 ContentLocation,
75 ContentRange,
76 ContentSecurityPolicy,
77 ContentSecurityPolicyReportOnly,
78 ContentType,
79 Cookie,
80 CrossOriginEmbedderPolicy,
81 CrossOriginEmbedderPolicyReportOnly,
82 CrossOriginOpenerPolicy,
83 CrossOriginOpenerPolicyReportOnly,
84 CrossOriginResourcePolicy,
85 DASL,
86 Date,
87 DAV,
88 DeltaBase,
89 Depth,
90 Destination,
91 DifferentialID,
92 DPoP,
93 DPoPNonce,
94 EarlyData,
95 ETag,
96 Expect,
97 ExpectCT,
98 Expires,
99 Forwarded,
100 From,
101 Hobareg,
102 Host,
103 If,
104 IfMatch,
105 IfModifiedSince,
106 IfNoneMatch,
107 IfRange,
108 IfScheduleTagMatch,
109 IfUnmodifiedSince,
110 IM,
111 IncludeReferredTokenBindingID,
112 KeepAlive,
113 Label,
114 LastEventID,
115 LastModified,
116 Link,
117 Location,
118 LockToken,
119 MaxForwards,
120 MementoDatetime,
121 Meter,
122 MIMEVersion,
123 Negotiate,
124 NEL,
125 ODataEntityId,
126 ODataIsolation,
127 ODataMaxVersion,
128 ODataVersion,
129 OptionalWWWAuthenticate,
130 OrderingType,
131 Origin,
132 OriginAgentCluster,
133 OSCORE,
134 OSLCCoreVersion,
135 Overwrite,
136 PingFrom,
137 PingTo,
138 Position,
139 Prefer,
140 PreferenceApplied,
141 Priority,
142 ProxyAuthenticate,
143 ProxyAuthenticationInfo,
144 ProxyAuthorization,
145 ProxyStatus,
146 PublicKeyPins,
147 PublicKeyPinsReportOnly,
148 Range,
149 RedirectRef,
150 Referer,
151 Refresh,
152 ReplayNonce,
153 ReprDigest,
154 RetryAfter,
155 ScheduleReply,
156 ScheduleTag,
157 SecPurpose,
158 SecTokenBinding,
159 SecWebSocketAccept,
160 SecWebSocketExtensions,
161 SecWebSocketKey,
162 SecWebSocketProtocol,
163 SecWebSocketVersion,
164 Server,
165 ServerTiming,
166 SetCookie,
167 Signature,
168 SignatureInput,
169 SLUG,
170 SoapAction,
171 StatusURI,
172 StrictTransportSecurity,
173 Sunset,
174 SurrogateCapability,
175 SurrogateControl,
176 TCN,
177 TE,
178 Timeout,
179 Topic,
180 Traceparent,
181 Tracestate,
182 Trailer,
183 TransferEncoding,
184 TTL,
185 Upgrade,
186 Urgency,
187 UserAgent,
188 VariantVary,
189 Vary,
190 Via,
191 WantContentDigest,
192 WantReprDigest,
193 WWWAuthenticate,
194 XContentTypeOptions,
195 XFrameOptions,
196 // IANA Deprecated status:
197 AcceptCharset,
198 CPEPInfo,
199 Pragma,
200 ProtocolInfo,
201 ProtocolQuery,
202 };
203 Q_ENUM(WellKnownHeader)
204
205 Q_NETWORK_EXPORT QHttpHeaders() noexcept;
206 Q_NETWORK_EXPORT ~QHttpHeaders();
207
208 Q_NETWORK_EXPORT QHttpHeaders(const QHttpHeaders &other);
209 QHttpHeaders(QHttpHeaders &&other) noexcept = default;
210 Q_NETWORK_EXPORT QHttpHeaders &operator=(const QHttpHeaders &other);
211 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QHttpHeaders)
212 void swap(QHttpHeaders &other) noexcept { d.swap(other.d); }
213
214 Q_NETWORK_EXPORT bool append(QAnyStringView name, QAnyStringView value);
215 Q_NETWORK_EXPORT bool append(WellKnownHeader name, QAnyStringView value);
216
217 Q_NETWORK_EXPORT bool insert(qsizetype i, QAnyStringView name, QAnyStringView value);
218 Q_NETWORK_EXPORT bool insert(qsizetype i, WellKnownHeader name, QAnyStringView value);
219
220 Q_NETWORK_EXPORT bool replace(qsizetype i, QAnyStringView name, QAnyStringView newValue);
221 Q_NETWORK_EXPORT bool replace(qsizetype i, WellKnownHeader name, QAnyStringView newValue);
222
223 Q_NETWORK_EXPORT bool replaceOrAppend(QAnyStringView name, QAnyStringView newValue);
224 Q_NETWORK_EXPORT bool replaceOrAppend(WellKnownHeader name, QAnyStringView newValue);
225
226 Q_NETWORK_EXPORT bool contains(QAnyStringView name) const;
227 Q_NETWORK_EXPORT bool contains(WellKnownHeader name) const;
228
229 Q_NETWORK_EXPORT void clear();
230 Q_NETWORK_EXPORT void removeAll(QAnyStringView name);
231 Q_NETWORK_EXPORT void removeAll(WellKnownHeader name);
232 Q_NETWORK_EXPORT void removeAt(qsizetype i);
233
234 Q_NETWORK_EXPORT QByteArrayView value(QAnyStringView name, QByteArrayView defaultValue = {}) const noexcept;
235 Q_NETWORK_EXPORT QByteArrayView value(WellKnownHeader name, QByteArrayView defaultValue = {}) const noexcept;
236
237 Q_NETWORK_EXPORT QList<QByteArray> values(QAnyStringView name) const;
238 Q_NETWORK_EXPORT QList<QByteArray> values(WellKnownHeader name) const;
239
240 Q_NETWORK_EXPORT QByteArrayView valueAt(qsizetype i) const noexcept;
241 Q_NETWORK_EXPORT QLatin1StringView nameAt(qsizetype i) const noexcept;
242
243 Q_NETWORK_EXPORT QByteArray combinedValue(QAnyStringView name) const;
244 Q_NETWORK_EXPORT QByteArray combinedValue(WellKnownHeader name) const;
245
246 Q_NETWORK_EXPORT qsizetype size() const noexcept;
247 Q_NETWORK_EXPORT void reserve(qsizetype size);
248 bool isEmpty() const noexcept { return size() == 0; }
249
250 Q_NETWORK_EXPORT static QByteArrayView wellKnownHeaderName(WellKnownHeader name) noexcept;
251
252 Q_NETWORK_EXPORT static QHttpHeaders
253 fromListOfPairs(const QList<std::pair<QByteArray, QByteArray>> &headers);
254 Q_NETWORK_EXPORT static QHttpHeaders
255 fromMultiMap(const QMultiMap<QByteArray, QByteArray> &headers);
256 Q_NETWORK_EXPORT static QHttpHeaders
257 fromMultiHash(const QMultiHash<QByteArray, QByteArray> &headers);
258
259 Q_NETWORK_EXPORT QList<std::pair<QByteArray, QByteArray>> toListOfPairs() const;
260 Q_NETWORK_EXPORT QMultiMap<QByteArray, QByteArray> toMultiMap() const;
261 Q_NETWORK_EXPORT QMultiHash<QByteArray, QByteArray> toMultiHash() const;
262
263private:
264#ifndef QT_NO_DEBUG_STREAM
265 friend Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QHttpHeaders &headers);
266#endif
267 Q_ALWAYS_INLINE void verify([[maybe_unused]] qsizetype pos = 0,
268 [[maybe_unused]] qsizetype n = 1) const
269 {
270 Q_ASSERT(pos >= 0);
271 Q_ASSERT(pos <= size());
272 Q_ASSERT(n >= 0);
273 Q_ASSERT(n <= size() - pos);
274 }
275 QExplicitlySharedDataPointer<QHttpHeadersPrivate> d;
276};
277
278Q_DECLARE_SHARED(QHttpHeaders)
279
281
282#endif // QHTTPHEADERS_H
\inmodule QtCore
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
static void replaceOrAppend(Self &d, const HeaderName &name, const QByteArray &value)
void combinedValue(const HeaderName &name, QByteArray &result) const
static void removeAll(Self &d, const HeaderName &name)
QList< Header > headers
WellKnownHeader
List of well known headers as per \l {https://www.iana.org/assignments/http-fields}{IANA registry}.
void swap(QHttpHeaders &other) noexcept
Swaps this QHttpHeaders with other.
Definition qlist.h:75
\inmodule QtCore Represents a handle to a signal-slot (or signal-functor) connection.
b clear()
list append(new Employee("Blackpool", "Stephen"))
cache insert(employee->id(), employee)
set reserve(20000)
Combined button and popup list for selecting options.
#define Q_ALWAYS_INLINE
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static bool contains(const QJsonArray &haystack, unsigned needle)
Definition qopengl.cpp:116
GLenum GLsizei GLsizei GLint * values
[15]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint name
GLfloat n
static qreal valueAt(const QQuickRangeSlider *slider, qreal position)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(Class, ExportMacro)
#define Q_ENUM(x)
#define Q_GADGET_EXPORT(...)
ptrdiff_t qsizetype
Definition qtypes.h:165
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QSharedPointer< T > other(t)
[5]
this swap(other)