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/qhashfunctions.h>
12#include <QtCore/qmetaobject.h>
13#include <QtCore/qobjectdefs.h>
14#include <QtCore/qshareddata.h>
15#include <QtCore/qcontainerfwd.h>
16#include <QtCore/qspan.h>
17#include <QtCore/qcomparehelpers.h>
18
19#include <optional>
20
21QT_BEGIN_NAMESPACE
22
23class QDataStream;
24class QDebug;
25
27{
30
31 constexpr bool isValid() const noexcept
32 {
33 if (!start && !end)
34 return false;
35 if (start && start < 0)
36 return false;
37 if (end && end < 0)
38 return false;
39 if (start && end && *start > *end)
40 return false;
41 return true;
42 }
43
44#ifndef QT_NO_DEBUG_STREAM
46#endif
47
48private:
49 friend constexpr bool comparesEqual(const QHttpHeaderRange &lhs,
50 const QHttpHeaderRange &rhs) noexcept
51 {
52 return lhs.start == rhs.start && lhs.end == rhs.end;
53 }
55
57 {
59 }
60};
61
63QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QHttpHeadersPrivate, Q_NETWORK_EXPORT)
65{
66 Q_GADGET_EXPORT(Q_NETWORK_EXPORT)
67public:
68 enum class WellKnownHeader {
69 // IANA Permanent status:
242 // IANA Deprecated status:
248 };
249 Q_ENUM(WellKnownHeader)
250
253
255 QHttpHeaders(QHttpHeaders &&other) noexcept = default;
258 void swap(QHttpHeaders &other) noexcept { d.swap(other.d); }
259
261 Q_NETWORK_EXPORT bool append(WellKnownHeader name, QAnyStringView value);
262
263 Q_NETWORK_EXPORT bool insert(qsizetype i, QAnyStringView name, QAnyStringView value);
264 Q_NETWORK_EXPORT bool insert(qsizetype i, WellKnownHeader name, QAnyStringView value);
265
266 Q_NETWORK_EXPORT bool replace(qsizetype i, QAnyStringView name, QAnyStringView newValue);
267 Q_NETWORK_EXPORT bool replace(qsizetype i, WellKnownHeader name, QAnyStringView newValue);
268
269 Q_NETWORK_EXPORT bool replaceOrAppend(QAnyStringView name, QAnyStringView newValue);
270 Q_NETWORK_EXPORT bool replaceOrAppend(WellKnownHeader name, QAnyStringView newValue);
271
272 Q_NETWORK_EXPORT bool contains(QAnyStringView name) const;
273 Q_NETWORK_EXPORT bool contains(WellKnownHeader name) const;
274
275 Q_NETWORK_EXPORT void clear();
276 Q_NETWORK_EXPORT void removeAll(QAnyStringView name);
277 Q_NETWORK_EXPORT void removeAll(WellKnownHeader name);
278 Q_NETWORK_EXPORT void removeAt(qsizetype i);
279
280 Q_NETWORK_EXPORT QByteArrayView value(QAnyStringView name, QByteArrayView defaultValue = {}) const noexcept;
282
285
287 Q_NETWORK_EXPORT QLatin1StringView nameAt(qsizetype i) const noexcept;
288
289 Q_NETWORK_EXPORT QByteArray combinedValue(QAnyStringView name) const;
291
294
297
299
302
305
307
308 Q_NETWORK_EXPORT void setDateTimeValue(QAnyStringView name, const QDateTime &dateTime);
309 Q_NETWORK_EXPORT void setDateTimeValue(WellKnownHeader name, const QDateTime &dateTime);
310
312 Q_NETWORK_EXPORT void setRangeValues(QSpan<const QHttpHeaderRange> ranges);
313
314 Q_NETWORK_EXPORT qsizetype size() const noexcept;
315 Q_NETWORK_EXPORT void reserve(qsizetype size);
316 bool isEmpty() const noexcept { return size() == 0; }
317
318 Q_NETWORK_EXPORT static QByteArrayView wellKnownHeaderName(WellKnownHeader name) noexcept;
319
320 Q_NETWORK_EXPORT static QHttpHeaders
322 Q_NETWORK_EXPORT static QHttpHeaders
324 Q_NETWORK_EXPORT static QHttpHeaders
326
330
331private:
332#ifndef QT_NO_DEBUG_STREAM
334#endif
335
336#ifndef QT_NO_DATASTREAM
339#endif
340
341 Q_ALWAYS_INLINE void verify([[maybe_unused]] qsizetype pos = 0,
342 [[maybe_unused]] qsizetype n = 1) const
343 {
344 Q_ASSERT(pos >= 0);
345 Q_ASSERT(pos <= size());
346 Q_ASSERT(n >= 0);
347 Q_ASSERT(n <= size() - pos);
348 }
349 QExplicitlySharedDataPointer<QHttpHeadersPrivate> d;
350};
351
352Q_DECLARE_SHARED(QHttpHeaders)
353
354QT_END_NAMESPACE
355
356#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 void setRangeValues(QSpan< const QHttpHeaderRange > ranges)
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
QHttpHeaderRange represents a single byte range as used in the HTTP {Range} and {Content-Range}...
friend constexpr bool comparesEqual(const QHttpHeaderRange &lhs, const QHttpHeaderRange &rhs) noexcept
std::optional< qint64 > end
std::optional< qint64 > start
constexpr bool isValid() const noexcept
\variable std::optional<qint64> QHttpHeaderRange::start