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
102 User = 1000,
103 UserMax = 32767
104 };
105 enum CacheLoadControl {
106 AlwaysNetwork,
107 PreferNetwork,
108 PreferCache,
109 AlwaysCache
110 };
111 enum LoadControl {
112 Automatic = 0,
113 Manual
114 };
115
116 enum Priority {
117 HighPriority = 1,
118 NormalPriority = 3,
119 LowPriority = 5
120 };
121
122 enum RedirectPolicy {
123 ManualRedirectPolicy,
124 NoLessSafeRedirectPolicy,
125 SameOriginRedirectPolicy,
126 UserVerifiedRedirectPolicy
127 };
128
129
130 explicit QNetworkRequest(const QUrl &url = QUrl());
131 QNetworkRequest(const QNetworkRequest &other);
132 ~QNetworkRequest();
133#ifdef Q_COMPILER_RVALUE_REFS
134 QNetworkRequest &operator=(QNetworkRequest &&other) Q_DECL_NOTHROW { swap(other); return *this; }
135#endif
136 QNetworkRequest &operator=(const QNetworkRequest &other);
137
138 void swap(QNetworkRequest &other) Q_DECL_NOTHROW { 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
176private:
177 QSharedDataPointer<QNetworkRequestPrivate> d;
178 friend class QNetworkRequestPrivate;
179};
180
181Q_DECLARE_SHARED(QNetworkRequest)
182
183QT_END_NAMESPACE
184
185Q_DECLARE_METATYPE(QNetworkRequest)
186Q_DECLARE_METATYPE(QNetworkRequest::RedirectPolicy)
187
188#endif
189