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 QHTTPNETWORKREQUEST_H
41#define QHTTPNETWORKREQUEST_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists for the convenience
48// of the Network Access API. This header file may change from
49// version to version without notice, or even be removed.
50//
51// We mean it.
52//
53#include <QtNetwork/private/qtnetworkglobal_p.h>
54
55#include <private/qhttpnetworkheader_p.h>
56#include <QtNetwork/qnetworkrequest.h>
57#include <qmetatype.h>
58
59#ifndef Q_OS_WASM
60QT_REQUIRE_CONFIG(http);
61#endif
62
63QT_BEGIN_NAMESPACE
64
65class QNonContiguousByteDevice;
66
67class QHttpNetworkRequestPrivate;
68class Q_AUTOTEST_EXPORT QHttpNetworkRequest: public QHttpNetworkHeader
69{
70public:
71 enum Operation {
72 Options,
73 Get,
74 Head,
75 Post,
76 Put,
77 Delete,
78 Trace,
79 Connect,
80 Custom
81 };
82
83 enum Priority {
84 HighPriority,
85 NormalPriority,
86 LowPriority
87 };
88
89 explicit QHttpNetworkRequest(const QUrl &url = QUrl(), Operation operation = Get, Priority priority = NormalPriority);
90 QHttpNetworkRequest(const QHttpNetworkRequest &other);
91 virtual ~QHttpNetworkRequest();
92 QHttpNetworkRequest &operator=(const QHttpNetworkRequest &other);
93 bool operator==(const QHttpNetworkRequest &other) const;
94
95 QUrl url() const override;
96 void setUrl(const QUrl &url) override;
97
98 int majorVersion() const override;
99 int minorVersion() const override;
100
101 qint64 contentLength() const override;
102 void setContentLength(qint64 length) override;
103
104 QList<QPair<QByteArray, QByteArray> > header() const override;
105 QByteArray headerField(const QByteArray &name, const QByteArray &defaultValue = QByteArray()) const override;
106 void setHeaderField(const QByteArray &name, const QByteArray &data) override;
107 void prependHeaderField(const QByteArray &name, const QByteArray &data);
108 void clearHeaders();
109
110 Operation operation() const;
111 void setOperation(Operation operation);
112
113 QByteArray customVerb() const;
114 void setCustomVerb(const QByteArray &customOperation);
115
116 Priority priority() const;
117 void setPriority(Priority priority);
118
119 bool isPipeliningAllowed() const;
120 void setPipeliningAllowed(bool b);
121
122 bool isHTTP2Allowed() const;
123 void setHTTP2Allowed(bool b);
124
125 bool isHTTP2Direct() const;
126 void setHTTP2Direct(bool b);
127
128 bool withCredentials() const;
129 void setWithCredentials(bool b);
130
131 bool isSsl() const;
132 void setSsl(bool);
133
134 bool isPreConnect() const;
135 void setPreConnect(bool preConnect);
136
137 bool isFollowRedirects() const;
138 void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
139 QNetworkRequest::RedirectPolicy redirectPolicy() const;
140
141 int redirectCount() const;
142 void setRedirectCount(int count);
143
144 void setUploadByteDevice(QNonContiguousByteDevice *bd);
145 QNonContiguousByteDevice* uploadByteDevice() const;
146
147 QByteArray methodName() const;
148 QByteArray uri(bool throughProxy) const;
149
150 QString peerVerifyName() const;
151 void setPeerVerifyName(const QString &peerName);
152
153 bool ignoreDecompressionRatio();
154 void setIgnoreDecompressionRatio(bool enabled);
155private:
156 QSharedDataPointer<QHttpNetworkRequestPrivate> d;
157 friend class QHttpNetworkRequestPrivate;
158 friend class QHttpNetworkConnectionPrivate;
159 friend class QHttpNetworkConnectionChannel;
160 friend class QHttpProtocolHandler;
161 friend class QHttp2ProtocolHandler;
162 friend class QSpdyProtocolHandler;
163};
164
165class QHttpNetworkRequestPrivate : public QHttpNetworkHeaderPrivate
166{
167public:
168 QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op,
169 QHttpNetworkRequest::Priority pri, const QUrl &newUrl = QUrl());
170 QHttpNetworkRequestPrivate(const QHttpNetworkRequestPrivate &other);
171 ~QHttpNetworkRequestPrivate();
172 bool operator==(const QHttpNetworkRequestPrivate &other) const;
173
174 static QByteArray header(const QHttpNetworkRequest &request, bool throughProxy);
175
176 QHttpNetworkRequest::Operation operation;
177 QByteArray customVerb;
178 QHttpNetworkRequest::Priority priority;
179 mutable QNonContiguousByteDevice* uploadByteDevice;
180 bool autoDecompress;
181 bool pipeliningAllowed;
182 bool http2Allowed;
183 bool http2Direct;
184 bool withCredentials;
185 bool ssl;
186 bool preConnect;
187 bool ignoreDecompressionRatio = false;
188 int redirectCount;
189 QNetworkRequest::RedirectPolicy redirectPolicy;
190 QString peerVerifyName;
191};
192
193
194QT_END_NAMESPACE
195
196Q_DECLARE_METATYPE(QHttpNetworkRequest)
197
198#endif // QHTTPNETWORKREQUEST_H
199