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_H |
5 | #define QNETWORKREQUEST_H |
6 | |
7 | #include <QtNetwork/qtnetworkglobal.h> |
8 | #include <QtCore/QSharedDataPointer> |
9 | #include <QtCore/QString> |
10 | #include <QtCore/QUrl> |
11 | #include <QtCore/QVariant> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QSslConfiguration; |
16 | class QHttp2Configuration; |
17 | class QHttp1Configuration; |
18 | |
19 | class QNetworkRequestPrivate; |
20 | class Q_NETWORK_EXPORT QNetworkRequest |
21 | { |
22 | public: |
23 | enum { |
24 | , |
25 | , |
26 | , |
27 | , |
28 | , |
29 | , |
30 | , // added for QMultipartMessage |
31 | , |
32 | , |
33 | , |
34 | , |
35 | , |
36 | |
37 | }; |
38 | enum Attribute { |
39 | HttpStatusCodeAttribute, |
40 | HttpReasonPhraseAttribute, |
41 | RedirectionTargetAttribute, |
42 | ConnectionEncryptedAttribute, |
43 | CacheLoadControlAttribute, |
44 | CacheSaveControlAttribute, |
45 | SourceIsFromCacheAttribute, |
46 | DoNotBufferUploadDataAttribute, |
47 | HttpPipeliningAllowedAttribute, |
48 | HttpPipeliningWasUsedAttribute, |
49 | CustomVerbAttribute, |
50 | CookieLoadControlAttribute, |
51 | AuthenticationReuseAttribute, |
52 | CookieSaveControlAttribute, |
53 | MaximumDownloadBufferSizeAttribute, // internal |
54 | DownloadBufferAttribute, // internal |
55 | SynchronousRequestAttribute, // internal |
56 | BackgroundRequestAttribute, |
57 | EmitAllUploadProgressSignalsAttribute, |
58 | Http2AllowedAttribute, |
59 | Http2WasUsedAttribute, |
60 | OriginalContentLengthAttribute, |
61 | RedirectPolicyAttribute, |
62 | Http2DirectAttribute, |
63 | ResourceTypeAttribute, // internal |
64 | AutoDeleteReplyOnFinishAttribute, |
65 | ConnectionCacheExpiryTimeoutSecondsAttribute, |
66 | Http2CleartextAllowedAttribute, |
67 | UseCredentialsAttribute, |
68 | |
69 | User = 1000, |
70 | UserMax = 32767 |
71 | }; |
72 | enum CacheLoadControl { |
73 | AlwaysNetwork, |
74 | PreferNetwork, |
75 | PreferCache, |
76 | AlwaysCache |
77 | }; |
78 | enum LoadControl { |
79 | Automatic = 0, |
80 | Manual |
81 | }; |
82 | |
83 | enum Priority { |
84 | HighPriority = 1, |
85 | NormalPriority = 3, |
86 | LowPriority = 5 |
87 | }; |
88 | |
89 | enum RedirectPolicy { |
90 | ManualRedirectPolicy, |
91 | NoLessSafeRedirectPolicy, |
92 | SameOriginRedirectPolicy, |
93 | UserVerifiedRedirectPolicy |
94 | }; |
95 | |
96 | enum TransferTimeoutConstant { |
97 | DefaultTransferTimeoutConstant = 30000 |
98 | }; |
99 | |
100 | QNetworkRequest(); |
101 | explicit QNetworkRequest(const QUrl &url); |
102 | QNetworkRequest(const QNetworkRequest &other); |
103 | ~QNetworkRequest(); |
104 | QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; } |
105 | QNetworkRequest &operator=(const QNetworkRequest &other); |
106 | |
107 | void swap(QNetworkRequest &other) noexcept { d.swap(other&: other.d); } |
108 | |
109 | bool operator==(const QNetworkRequest &other) const; |
110 | inline bool operator!=(const QNetworkRequest &other) const |
111 | { return !operator==(other); } |
112 | |
113 | QUrl url() const; |
114 | void setUrl(const QUrl &url); |
115 | |
116 | // "cooked" headers |
117 | QVariant (KnownHeaders ) const; |
118 | void (KnownHeaders , const QVariant &value); |
119 | |
120 | // raw headers: |
121 | bool (const QByteArray &) const; |
122 | QList<QByteArray> () const; |
123 | QByteArray (const QByteArray &) const; |
124 | void (const QByteArray &, const QByteArray &value); |
125 | |
126 | // attributes |
127 | QVariant attribute(Attribute code, const QVariant &defaultValue = QVariant()) const; |
128 | void setAttribute(Attribute code, const QVariant &value); |
129 | |
130 | #ifndef QT_NO_SSL |
131 | QSslConfiguration sslConfiguration() const; |
132 | void setSslConfiguration(const QSslConfiguration &configuration); |
133 | #endif |
134 | |
135 | void setOriginatingObject(QObject *object); |
136 | QObject *originatingObject() const; |
137 | |
138 | Priority priority() const; |
139 | void setPriority(Priority priority); |
140 | |
141 | // HTTP redirect related |
142 | int maximumRedirectsAllowed() const; |
143 | void setMaximumRedirectsAllowed(int maximumRedirectsAllowed); |
144 | |
145 | QString peerVerifyName() const; |
146 | void setPeerVerifyName(const QString &peerName); |
147 | #if QT_CONFIG(http) |
148 | QHttp1Configuration http1Configuration() const; |
149 | void setHttp1Configuration(const QHttp1Configuration &configuration); |
150 | |
151 | QHttp2Configuration http2Configuration() const; |
152 | void setHttp2Configuration(const QHttp2Configuration &configuration); |
153 | |
154 | qint64 decompressedSafetyCheckThreshold() const; |
155 | void setDecompressedSafetyCheckThreshold(qint64 threshold); |
156 | #endif // QT_CONFIG(http) |
157 | |
158 | #if QT_CONFIG(http) || defined (Q_OS_WASM) |
159 | int transferTimeout() const; |
160 | void setTransferTimeout(int timeout = DefaultTransferTimeoutConstant); |
161 | #endif // QT_CONFIG(http) || defined (Q_OS_WASM) |
162 | private: |
163 | QSharedDataPointer<QNetworkRequestPrivate> d; |
164 | friend class QNetworkRequestPrivate; |
165 | }; |
166 | |
167 | Q_DECLARE_SHARED(QNetworkRequest) |
168 | |
169 | QT_END_NAMESPACE |
170 | |
171 | QT_DECL_METATYPE_EXTERN(QNetworkRequest, Q_NETWORK_EXPORT) |
172 | QT_DECL_METATYPE_EXTERN_TAGGED(QNetworkRequest::RedirectPolicy, |
173 | QNetworkRequest__RedirectPolicy, Q_NETWORK_EXPORT) |
174 | |
175 | #endif |
176 | |