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_P_H |
5 | #define QNETWORKREQUEST_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists for the convenience |
12 | // of the Network Access API. This header file may change from |
13 | // version to version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QtNetwork/private/qtnetworkglobal_p.h> |
19 | #include <QtNetwork/qhttpheaders.h> |
20 | #include "qnetworkrequest.h" |
21 | #include "QtCore/qbytearray.h" |
22 | #include "QtCore/qlist.h" |
23 | #include "QtCore/qhash.h" |
24 | #include "QtCore/qshareddata.h" |
25 | #include "QtCore/qsharedpointer.h" |
26 | #include "QtCore/qpointer.h" |
27 | |
28 | QT_BEGIN_NAMESPACE |
29 | |
30 | class QNetworkCookie; |
31 | |
32 | // this is the common part between QNetworkRequestPrivate, QNetworkReplyPrivate and QHttpPartPrivate |
33 | class QNetworkHeadersPrivate |
34 | { |
35 | public: |
36 | typedef QPair<QByteArray, QByteArray> RawHeaderPair; |
37 | typedef QList<RawHeaderPair> RawHeadersList; |
38 | typedef QHash<QNetworkRequest::KnownHeaders, QVariant> CookedHeadersMap; |
39 | typedef QHash<QNetworkRequest::Attribute, QVariant> AttributesMap; |
40 | |
41 | mutable struct { |
42 | RawHeadersList headersList; |
43 | bool isCached = false; |
44 | } rawHeaderCache; |
45 | |
46 | QHttpHeaders httpHeaders; |
47 | CookedHeadersMap cookedHeaders; |
48 | AttributesMap attributes; |
49 | QPointer<QObject> originatingObject; |
50 | |
51 | const RawHeadersList &allRawHeaders() const; |
52 | QList<QByteArray> rawHeadersKeys() const; |
53 | QByteArray rawHeader(QAnyStringView headerName) const; |
54 | void setRawHeader(const QByteArray &key, const QByteArray &value); |
55 | void setCookedHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); |
56 | |
57 | QHttpHeaders headers() const; |
58 | void setHeaders(const QHttpHeaders &newHeaders); |
59 | void setHeaders(QHttpHeaders &&newHeaders); |
60 | void setHeader(QHttpHeaders::WellKnownHeader name, QByteArrayView value); |
61 | |
62 | void clearHeaders(); |
63 | |
64 | static QDateTime fromHttpDate(QByteArrayView value); |
65 | static QByteArray toHttpDate(const QDateTime &dt); |
66 | |
67 | static std::optional<qint64> toInt(QByteArrayView value); |
68 | |
69 | typedef QList<QNetworkCookie> NetworkCookieList; |
70 | static QByteArray fromCookieList(const NetworkCookieList &cookies); |
71 | static std::optional<NetworkCookieList> toSetCookieList(const QList<QByteArray> &values); |
72 | static std::optional<NetworkCookieList> toCookieList(const QList<QByteArray> &values); |
73 | |
74 | static RawHeadersList fromHttpToRaw(const QHttpHeaders &headers); |
75 | static QHttpHeaders fromRawToHttp(const RawHeadersList &raw); |
76 | |
77 | private: |
78 | void invalidateHeaderCache(); |
79 | |
80 | void setCookedFromHttp(const QHttpHeaders &newHeaders); |
81 | void parseAndSetHeader(QByteArrayView key, QByteArrayView value); |
82 | void parseAndSetHeader(QNetworkRequest::KnownHeaders key, QByteArrayView value); |
83 | |
84 | }; |
85 | |
86 | Q_DECLARE_TYPEINFO(QNetworkHeadersPrivate::RawHeaderPair, Q_RELOCATABLE_TYPE); |
87 | |
88 | QT_END_NAMESPACE |
89 | |
90 | |
91 | #endif |
92 |
Definitions
Learn Advanced QML with KDAB
Find out more