Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// 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
17
18class QDebug;
19
21QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QHttpHeadersPrivate, Q_NETWORK_EXPORT)
23{
24 Q_GADGET_EXPORT(Q_NETWORK_EXPORT)
25public:
26 enum class WellKnownHeader {
27 // IANA Permanent status:
200 // IANA Deprecated status:
206 };
207 Q_ENUM(WellKnownHeader)
208
211
213 QHttpHeaders(QHttpHeaders &&other) noexcept = default;
216 void swap(QHttpHeaders &other) noexcept { d.swap(other.d); }
217
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;
240
243
245 Q_NETWORK_EXPORT QLatin1StringView nameAt(qsizetype i) const noexcept;
246
247 Q_NETWORK_EXPORT QByteArray combinedValue(QAnyStringView name) const;
249
250 Q_NETWORK_EXPORT std::optional<qint64> intValue(QAnyStringView name) const noexcept;
252
255
257
260
263
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 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
277 Q_NETWORK_EXPORT static QHttpHeaders
279 Q_NETWORK_EXPORT static QHttpHeaders
281
285
286private:
287#ifndef QT_NO_DEBUG_STREAM
289#endif
290 Q_ALWAYS_INLINE void verify([[maybe_unused]] qsizetype pos = 0,
291 [[maybe_unused]] qsizetype n = 1) const
292 {
293 Q_ASSERT(pos >= 0);
294 Q_ASSERT(pos <= size());
295 Q_ASSERT(n >= 0);
296 Q_ASSERT(n <= size() - pos);
297 }
298 QExplicitlySharedDataPointer<QHttpHeadersPrivate> d;
299};
300
301Q_DECLARE_SHARED(QHttpHeaders)
302
303QT_END_NAMESPACE
304
305#endif // QHTTPHEADERS_H
Q_NETWORK_EXPORT void clear()
Clears all header entries.
bool isEmpty() const noexcept
Returns true if the headers have size 0; otherwise returns false.
Q_NETWORK_EXPORT bool insert(qsizetype i, QAnyStringView name, QAnyStringView value)
Inserts a header entry at index i, with name and value.
Q_NETWORK_EXPORT bool contains(QAnyStringView name) const
Returns whether the headers contain header with name.
Q_NETWORK_EXPORT ~QHttpHeaders()
Disposes of the headers object.
Q_NETWORK_EXPORT void removeAll(QAnyStringView name)
Removes the header name.
Q_NETWORK_EXPORT bool replaceOrAppend(QAnyStringView name, QAnyStringView newValue)
Q_NETWORK_EXPORT bool replace(qsizetype i, QAnyStringView name, QAnyStringView newValue)
Replaces the header entry at index i, with name and newValue.
Q_NETWORK_EXPORT void reserve(qsizetype size)
Attempts to allocate memory for at least size header entries.
Q_NETWORK_EXPORT void removeAt(qsizetype i)
Removes the header at index i.
QHttpHeaders(QHttpHeaders &&other) noexcept=default
Move-constructs the object from other, which will be left \l{isEmpty()}{empty}.
Q_NETWORK_EXPORT void setDateTimeValue(QAnyStringView name, const QDateTime &dateTime)
Q_NETWORK_EXPORT bool append(WellKnownHeader name, QAnyStringView value)
static QByteArrayView unescapeMaxAge(QByteArrayView value)
Definition qhsts.cpp:292
static bool isCTL(int c)
Definition qhsts.cpp:251
static bool isLWS(int c)
Definition qhsts.cpp:259
static bool isCHAR(int c)
Definition qhsts.cpp:245
static bool isTEXT(char c)
Definition qhsts.cpp:274
static bool isTOKEN(char c)
Definition qhsts.cpp:301
static bool isSeparator(char c)
Definition qhsts.cpp:281