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
59QT_REQUIRE_CONFIG(http);
60
61QT_BEGIN_NAMESPACE
62
63class QNonContiguousByteDevice;
64
65class QHttpNetworkRequestPrivate;
66class Q_AUTOTEST_EXPORT QHttpNetworkRequest: public QHttpNetworkHeader
67{
68public:
69 enum Operation {
70 Options,
71 Get,
72 Head,
73 Post,
74 Put,
75 Delete,
76 Trace,
77 Connect,
78 Custom
79 };
80
81 enum Priority {
82 HighPriority,
83 NormalPriority,
84 LowPriority
85 };
86
87 explicit QHttpNetworkRequest(const QUrl &url = QUrl(), Operation operation = Get, Priority priority = NormalPriority);
88 QHttpNetworkRequest(const QHttpNetworkRequest &other);
89 virtual ~QHttpNetworkRequest();
90 QHttpNetworkRequest &operator=(const QHttpNetworkRequest &other);
91 bool operator==(const QHttpNetworkRequest &other) const;
92
93 QUrl url() const override;
94 void setUrl(const QUrl &url) override;
95
96 int majorVersion() const override;
97 int minorVersion() const override;
98
99 qint64 contentLength() const override;
100 void setContentLength(qint64 length) override;
101
102 QList<QPair<QByteArray, QByteArray> > header() const override;
103 QByteArray headerField(const QByteArray &name, const QByteArray &defaultValue = QByteArray()) const override;
104 void setHeaderField(const QByteArray &name, const QByteArray &data) override;
105 void prependHeaderField(const QByteArray &name, const QByteArray &data);
106
107 Operation operation() const;
108 void setOperation(Operation operation);
109
110 QByteArray customVerb() const;
111 void setCustomVerb(const QByteArray &customOperation);
112
113 Priority priority() const;
114 void setPriority(Priority priority);
115
116 bool isPipeliningAllowed() const;
117 void setPipeliningAllowed(bool b);
118
119 bool isSPDYAllowed() const;
120 void setSPDYAllowed(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);
152private:
153 QSharedDataPointer<QHttpNetworkRequestPrivate> d;
154 friend class QHttpNetworkRequestPrivate;
155 friend class QHttpNetworkConnectionPrivate;
156 friend class QHttpNetworkConnectionChannel;
157 friend class QHttpProtocolHandler;
158 friend class QHttp2ProtocolHandler;
159 friend class QSpdyProtocolHandler;
160};
161
162class QHttpNetworkRequestPrivate : public QHttpNetworkHeaderPrivate
163{
164public:
165 QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op,
166 QHttpNetworkRequest::Priority pri, const QUrl &newUrl = QUrl());
167 QHttpNetworkRequestPrivate(const QHttpNetworkRequestPrivate &other);
168 ~QHttpNetworkRequestPrivate();
169 bool operator==(const QHttpNetworkRequestPrivate &other) const;
170
171 static QByteArray header(const QHttpNetworkRequest &request, bool throughProxy);
172
173 QHttpNetworkRequest::Operation operation;
174 QByteArray customVerb;
175 QHttpNetworkRequest::Priority priority;
176 mutable QNonContiguousByteDevice* uploadByteDevice;
177 bool autoDecompress;
178 bool pipeliningAllowed;
179 bool spdyAllowed;
180 bool http2Allowed;
181 bool http2Direct;
182 bool withCredentials;
183 bool ssl;
184 bool preConnect;
185 int redirectCount;
186 QNetworkRequest::RedirectPolicy redirectPolicy;
187 QString peerVerifyName;
188};
189
190
191QT_END_NAMESPACE
192
193Q_DECLARE_METATYPE(QHttpNetworkRequest)
194
195#endif // QHTTPNETWORKREQUEST_H
196