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;
52
53class QNetworkRequestPrivate;
54class Q_NETWORK_EXPORT QNetworkRequest
55{
56public:
57 enum KnownHeaders {
58 ContentTypeHeader,
59 ContentLengthHeader,
60 LocationHeader,
61 LastModifiedHeader,
62 CookieHeader,
63 SetCookieHeader,
64 ContentDispositionHeader, // added for QMultipartMessage
65 UserAgentHeader,
66 ServerHeader,
67 IfModifiedSinceHeader,
68 ETagHeader,
69 IfMatchHeader,
70 IfNoneMatchHeader
71 };
72 enum Attribute {
73 HttpStatusCodeAttribute,
74 HttpReasonPhraseAttribute,
75 RedirectionTargetAttribute,
76 ConnectionEncryptedAttribute,
77 CacheLoadControlAttribute,
78 CacheSaveControlAttribute,
79 SourceIsFromCacheAttribute,
80 DoNotBufferUploadDataAttribute,
81 HttpPipeliningAllowedAttribute,
82 HttpPipeliningWasUsedAttribute,
83 CustomVerbAttribute,
84 CookieLoadControlAttribute,
85 AuthenticationReuseAttribute,
86 CookieSaveControlAttribute,
87 MaximumDownloadBufferSizeAttribute, // internal
88 DownloadBufferAttribute, // internal
89 SynchronousRequestAttribute, // internal
90 BackgroundRequestAttribute,
91 SpdyAllowedAttribute,
92 SpdyWasUsedAttribute,
93 EmitAllUploadProgressSignalsAttribute,
94 FollowRedirectsAttribute,
95 HTTP2AllowedAttribute,
96 HTTP2WasUsedAttribute,
97 OriginalContentLengthAttribute,
98 RedirectPolicyAttribute,
99 Http2DirectAttribute,
100 ResourceTypeAttribute, // internal
101 AutoDeleteReplyOnFinishAttribute,
102
103 User = 1000,
104 UserMax = 32767
105 };
106 enum CacheLoadControl {
107 AlwaysNetwork,
108 PreferNetwork,
109 PreferCache,
110 AlwaysCache
111 };
112 enum LoadControl {
113 Automatic = 0,
114 Manual
115 };
116
117 enum Priority {
118 HighPriority = 1,
119 NormalPriority = 3,
120 LowPriority = 5
121 };
122
123 enum RedirectPolicy {
124 ManualRedirectPolicy,
125 NoLessSafeRedirectPolicy,
126 SameOriginRedirectPolicy,
127 UserVerifiedRedirectPolicy
128 };
129
130
131 QNetworkRequest();
132 explicit QNetworkRequest(const QUrl &url);
133 QNetworkRequest(const QNetworkRequest &other);
134 ~QNetworkRequest();
135 QNetworkRequest &operator=(QNetworkRequest &&other) noexcept { swap(other); return *this; }
136 QNetworkRequest &operator=(const QNetworkRequest &other);
137
138 void swap(QNetworkRequest &other) noexcept { qSwap(d, other.d); }
139
140 bool operator==(const QNetworkRequest &other) const;
141 inline bool operator!=(const QNetworkRequest &other) const
142 { return !operator==(other); }
143
144 QUrl url() const;
145 void setUrl(const QUrl &url);
146
147 // "cooked" headers
148 QVariant header(KnownHeaders header) const;
149 void setHeader(KnownHeaders header, const QVariant &value);
150
151 // raw headers:
152 bool hasRawHeader(const QByteArray &headerName) const;
153 QList<QByteArray> rawHeaderList() const;
154 QByteArray rawHeader(const QByteArray &headerName) const;
155 void setRawHeader(const QByteArray &headerName, const QByteArray &value);
156
157 // attributes
158 QVariant attribute(Attribute code, const QVariant &defaultValue = QVariant()) const;
159 void setAttribute(Attribute code, const QVariant &value);
160
161#ifndef QT_NO_SSL
162 QSslConfiguration sslConfiguration() const;
163 void setSslConfiguration(const QSslConfiguration &configuration);
164#endif
165
166 void setOriginatingObject(QObject *object);
167 QObject *originatingObject() const;
168
169 Priority priority() const;
170 void setPriority(Priority priority);
171
172 // HTTP redirect related
173 int maximumRedirectsAllowed() const;
174 void setMaximumRedirectsAllowed(int maximumRedirectsAllowed);
175
176 QString peerVerifyName() const;
177 void setPeerVerifyName(const QString &peerName);
178private:
179 QSharedDataPointer<QNetworkRequestPrivate> d;
180 friend class QNetworkRequestPrivate;
181};
182
183Q_DECLARE_SHARED(QNetworkRequest)
184
185QT_END_NAMESPACE
186
187Q_DECLARE_METATYPE(QNetworkRequest)
188Q_DECLARE_METATYPE(QNetworkRequest::RedirectPolicy)
189
190#endif
191