1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QHTTPNETWORKREQUEST_H
6#define QHTTPNETWORKREQUEST_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18#include <QtNetwork/private/qtnetworkglobal_p.h>
19
20#include <private/qhttpnetworkheader_p.h>
21#include <QtNetwork/qnetworkrequest.h>
22#include <qmetatype.h>
23
24#ifndef Q_OS_WASM
25QT_REQUIRE_CONFIG(http);
26#endif
27
28QT_BEGIN_NAMESPACE
29
30class QNonContiguousByteDevice;
31
32class QHttpNetworkRequestPrivate;
33class Q_AUTOTEST_EXPORT QHttpNetworkRequest: public QHttpNetworkHeader
34{
35public:
36 enum Operation {
37 Options,
38 Get,
39 Head,
40 Post,
41 Put,
42 Delete,
43 Trace,
44 Connect,
45 Custom
46 };
47
48 enum Priority {
49 HighPriority,
50 NormalPriority,
51 LowPriority
52 };
53
54 explicit QHttpNetworkRequest(const QUrl &url = QUrl(), Operation operation = Get, Priority priority = NormalPriority);
55 QHttpNetworkRequest(const QHttpNetworkRequest &other);
56 ~QHttpNetworkRequest() override;
57 QHttpNetworkRequest &operator=(const QHttpNetworkRequest &other);
58 bool operator==(const QHttpNetworkRequest &other) const;
59
60 QUrl url() const override;
61 void setUrl(const QUrl &url) override;
62
63 int majorVersion() const override;
64 int minorVersion() const override;
65
66 qint64 contentLength() const override;
67 void setContentLength(qint64 length) override;
68
69 QHttpHeaders header() const override;
70 QByteArray headerField(QByteArrayView name, const QByteArray &defaultValue = QByteArray()) const override;
71 void setHeaderField(const QByteArray &name, const QByteArray &data) override;
72 void prependHeaderField(const QByteArray &name, const QByteArray &data);
73 void clearHeaders();
74
75 Operation operation() const;
76 void setOperation(Operation operation);
77
78 QByteArray customVerb() const;
79 void setCustomVerb(const QByteArray &customOperation);
80
81 Priority priority() const;
82 void setPriority(Priority priority);
83
84 bool isPipeliningAllowed() const;
85 void setPipeliningAllowed(bool b);
86
87 bool isHTTP2Allowed() const;
88 void setHTTP2Allowed(bool b);
89
90 bool isHTTP2Direct() const;
91 void setHTTP2Direct(bool b);
92
93 bool isH2cAllowed() const;
94 void setH2cAllowed(bool b);
95
96 bool withCredentials() const;
97 void setWithCredentials(bool b);
98
99 bool isSsl() const;
100 void setSsl(bool);
101
102 bool isPreConnect() const;
103 void setPreConnect(bool preConnect);
104
105 bool isFollowRedirects() const;
106 void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
107 QNetworkRequest::RedirectPolicy redirectPolicy() const;
108
109 int redirectCount() const;
110 void setRedirectCount(int count);
111
112 void setUploadByteDevice(QNonContiguousByteDevice *bd);
113 QNonContiguousByteDevice* uploadByteDevice() const;
114
115 QByteArray methodName() const;
116 QByteArray uri(bool throughProxy) const;
117
118 QString peerVerifyName() const;
119 void setPeerVerifyName(const QString &peerName);
120
121 QString fullLocalServerName() const;
122 void setFullLocalServerName(const QString &fullServerName);
123
124 bool methodIsIdempotent() const;
125
126private:
127 QSharedDataPointer<QHttpNetworkRequestPrivate> d;
128 friend class QHttpNetworkRequestPrivate;
129 friend class QHttpNetworkConnectionPrivate;
130 friend class QHttpNetworkConnectionChannel;
131 friend class QHttpProtocolHandler;
132 friend class QHttp2ProtocolHandler;
133 friend class QSpdyProtocolHandler;
134};
135
136class QHttpNetworkRequestPrivate : public QHttpNetworkHeaderPrivate
137{
138public:
139 QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op,
140 QHttpNetworkRequest::Priority pri, const QUrl &newUrl = QUrl());
141 QHttpNetworkRequestPrivate(const QHttpNetworkRequestPrivate &other);
142 ~QHttpNetworkRequestPrivate();
143 bool operator==(const QHttpNetworkRequestPrivate &other) const;
144
145 static QByteArray header(const QHttpNetworkRequest &request, bool throughProxy);
146
147 QHttpNetworkRequest::Operation operation;
148 QByteArray customVerb;
149 QString fullLocalServerName; // for local sockets
150 QHttpNetworkRequest::Priority priority;
151 mutable QNonContiguousByteDevice* uploadByteDevice;
152 bool autoDecompress;
153 bool pipeliningAllowed;
154 bool http2Allowed;
155 bool http2Direct;
156 bool h2cAllowed = false;
157 bool withCredentials;
158 bool ssl = false;
159 bool preConnect;
160 bool needResendWithCredentials = false;
161 int redirectCount;
162 QNetworkRequest::RedirectPolicy redirectPolicy;
163 QString peerVerifyName;
164};
165
166
167QT_END_NAMESPACE
168
169QT_DECL_METATYPE_EXTERN(QHttpNetworkRequest, Q_AUTOTEST_EXPORT)
170
171#endif // QHTTPNETWORKREQUEST_H
172

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