1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtNetwork module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QNETWORKREQUEST_H
41#define QNETWORKREQUEST_H
42
43#include <QtNetwork/qtnetworkglobal.h>
44#include <QtCore/QSharedDataPointer>
45#include <QtCore/QString>
46#include <QtCore/QUrl>
47#include <QtCore/QVariant>
48
49QT_BEGIN_NAMESPACE
50
51class QSslConfiguration;
52class QHttp2Configuration;
53
54class QNetworkRequestPrivate;
55class Q_NETWORK_EXPORT QNetworkRequest
56{
57public:
58 enum KnownHeaders {
59 ContentTypeHeader,
60 ContentLengthHeader,
61 LocationHeader,
62 LastModifiedHeader,
63 CookieHeader,
64 SetCookieHeader,
65 ContentDispositionHeader, // added for QMultipartMessage
66 UserAgentHeader,
67 ServerHeader,
68 IfModifiedSinceHeader,
69 ETagHeader,
70 IfMatchHeader,
71 IfNoneMatchHeader
72 };
73 enum Attribute {
74 HttpStatusCodeAttribute,
75 HttpReasonPhraseAttribute,
76 RedirectionTargetAttribute,
77 ConnectionEncryptedAttribute,
78 CacheLoadControlAttribute,
79 CacheSaveControlAttribute,
80 SourceIsFromCacheAttribute,
81 DoNotBufferUploadDataAttribute,
82 HttpPipeliningAllowedAttribute,
83 HttpPipeliningWasUsedAttribute,
84 CustomVerbAttribute,
85 CookieLoadControlAttribute,
86 AuthenticationReuseAttribute,
87 CookieSaveControlAttribute,
88 MaximumDownloadBufferSizeAttribute, // internal
89 DownloadBufferAttribute, // internal
90 SynchronousRequestAttribute, // internal
91 BackgroundRequestAttribute,
92#if QT_DEPRECATED_SINCE(5, 15)
93 SpdyAllowedAttribute,
94 SpdyWasUsedAttribute,
95#endif // QT_DEPRECATED_SINCE(5, 15)
96 EmitAllUploadProgressSignalsAttribute = BackgroundRequestAttribute + 3,
97 FollowRedirectsAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use RedirectPolicyAttribute"),
98 Http2AllowedAttribute,
99 Http2WasUsedAttribute,
100#if QT_DEPRECATED_SINCE(5, 15)
101 HTTP2AllowedAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use Http2AllowedAttribute") = Http2AllowedAttribute,
102 HTTP2WasUsedAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use Http2WasUsedAttribute"),
103#endif // QT_DEPRECATED_SINCE(5, 15)
104 OriginalContentLengthAttribute,
105 RedirectPolicyAttribute,
106 Http2DirectAttribute,
107 ResourceTypeAttribute, // internal
108 AutoDeleteReplyOnFinishAttribute,
109
110 User = 1000,
111 UserMax = 32767
112 };
113 enum CacheLoadControl {
114 AlwaysNetwork,
115 PreferNetwork,
116 PreferCache,
117 AlwaysCache
118 };
119 enum LoadControl {
120 Automatic = 0,
121 Manual
122 };
123
124 enum Priority {
125 HighPriority = 1,
126 NormalPriority = 3,
127 LowPriority = 5
128 };
129
130 enum RedirectPolicy {
131 ManualRedirectPolicy,
132 NoLessSafeRedirectPolicy,
133 SameOriginRedirectPolicy,
134 UserVerifiedRedirectPolicy
135 };
136
137 enum TransferTimeoutConstant {
138 DefaultTransferTimeoutConstant = 30000
139 };
140
141 QNetworkRequest();
142 explicit QNetworkRequest(const QUrl &url);
143 QNetworkRequest(const QNetworkRequest &other);
144 ~QNetworkRequest();
145 QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; }
146 QNetworkRequest &operator=(const QNetworkRequest &other);
147
148 void swap(QNetworkRequest &other) noexcept { qSwap(value1&: d, value2&: other.d); }
149
150 bool operator==(const QNetworkRequest &other) const;
151 inline bool operator!=(const QNetworkRequest &other) const
152 { return !operator==(other); }
153
154 QUrl url() const;
155 void setUrl(const QUrl &url);
156
157 // "cooked" headers
158 QVariant header(KnownHeaders header) const;
159 void setHeader(KnownHeaders header, const QVariant &value);
160
161 // raw headers:
162 bool hasRawHeader(const QByteArray &headerName) const;
163 QList<QByteArray> rawHeaderList() const;
164 QByteArray rawHeader(const QByteArray &headerName) const;
165 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
166
167 // attributes
168 QVariant attribute(Attribute code, const QVariant &defaultValue = QVariant()) const;
169 void setAttribute(Attribute code, const QVariant &value);
170
171#ifndef QT_NO_SSL
172 QSslConfiguration sslConfiguration() const;
173 void setSslConfiguration(const QSslConfiguration &configuration);
174#endif
175
176 void setOriginatingObject(QObject *object);
177 QObject *originatingObject() const;
178
179 Priority priority() const;
180 void setPriority(Priority priority);
181
182 // HTTP redirect related
183 int maximumRedirectsAllowed() const;
184 void setMaximumRedirectsAllowed(int maximumRedirectsAllowed);
185
186 QString peerVerifyName() const;
187 void setPeerVerifyName(const QString &peerName);
188#if QT_CONFIG(http) || defined(Q_CLANG_QDOC)
189 QHttp2Configuration http2Configuration() const;
190 void setHttp2Configuration(const QHttp2Configuration &configuration);
191#endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC)
192#if QT_CONFIG(http) || defined(Q_CLANG_QDOC) || defined (Q_OS_WASM)
193 int transferTimeout() const;
194 void setTransferTimeout(int timeout = DefaultTransferTimeoutConstant);
195#endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC) || defined (Q_OS_WASM)
196private:
197 QSharedDataPointer<QNetworkRequestPrivate> d;
198 friend class QNetworkRequestPrivate;
199};
200
201Q_DECLARE_SHARED(QNetworkRequest)
202
203QT_END_NAMESPACE
204
205Q_DECLARE_METATYPE(QNetworkRequest)
206Q_DECLARE_METATYPE(QNetworkRequest::RedirectPolicy)
207
208#endif
209

source code of qtbase/src/network/access/qnetworkrequest.h