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 QNETWORKACCESSMANAGER_H
41#define QNETWORKACCESSMANAGER_H
42
43#include <QtNetwork/qtnetworkglobal.h>
44#include <QtNetwork/qnetworkrequest.h>
45#include <QtCore/QString>
46#include <QtCore/QVector>
47#include <QtCore/QObject>
48#ifndef QT_NO_SSL
49#include <QtNetwork/QSslConfiguration>
50#include <QtNetwork/QSslPreSharedKeyAuthenticator>
51#endif
52
53QT_BEGIN_NAMESPACE
54
55class QIODevice;
56class QAbstractNetworkCache;
57class QAuthenticator;
58class QByteArray;
59template<typename T> class QList;
60class QNetworkCookie;
61class QNetworkCookieJar;
62class QNetworkReply;
63class QNetworkProxy;
64class QNetworkProxyFactory;
65class QSslError;
66class QHstsPolicy;
67#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
68class QNetworkConfiguration;
69#endif
70class QHttpMultiPart;
71
72class QNetworkReplyImplPrivate;
73class QNetworkAccessManagerPrivate;
74class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
75{
76 Q_OBJECT
77
78#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
79 Q_PROPERTY(NetworkAccessibility networkAccessible READ networkAccessible WRITE setNetworkAccessible NOTIFY networkAccessibleChanged)
80#endif
81
82public:
83 enum Operation {
84 HeadOperation = 1,
85 GetOperation,
86 PutOperation,
87 PostOperation,
88 DeleteOperation,
89 CustomOperation,
90
91 UnknownOperation = 0
92 };
93
94#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
95 enum QT_DEPRECATED_NETWORK_API_5_15 NetworkAccessibility {
96 UnknownAccessibility = -1,
97 NotAccessible = 0,
98 Accessible = 1
99 };
100QT_WARNING_PUSH
101QT_WARNING_DISABLE_DEPRECATED
102 Q_ENUM(NetworkAccessibility)
103QT_WARNING_POP
104#endif
105
106 explicit QNetworkAccessManager(QObject *parent = nullptr);
107 ~QNetworkAccessManager();
108
109 // ### Qt 6: turn into virtual
110 QStringList supportedSchemes() const;
111
112 void clearAccessCache();
113
114 void clearConnectionCache();
115
116#ifndef QT_NO_NETWORKPROXY
117 QNetworkProxy proxy() const;
118 void setProxy(const QNetworkProxy &proxy);
119 QNetworkProxyFactory *proxyFactory() const;
120 void setProxyFactory(QNetworkProxyFactory *factory);
121#endif
122
123 QAbstractNetworkCache *cache() const;
124 void setCache(QAbstractNetworkCache *cache);
125
126 QNetworkCookieJar *cookieJar() const;
127 void setCookieJar(QNetworkCookieJar *cookieJar);
128
129 void setStrictTransportSecurityEnabled(bool enabled);
130 bool isStrictTransportSecurityEnabled() const;
131 void enableStrictTransportSecurityStore(bool enabled, const QString &storeDir = QString());
132 bool isStrictTransportSecurityStoreEnabled() const;
133 void addStrictTransportSecurityHosts(const QVector<QHstsPolicy> &knownHosts);
134 QVector<QHstsPolicy> strictTransportSecurityHosts() const;
135
136 QNetworkReply *head(const QNetworkRequest &request);
137 QNetworkReply *get(const QNetworkRequest &request);
138 QNetworkReply *post(const QNetworkRequest &request, QIODevice *data);
139 QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data);
140 QNetworkReply *put(const QNetworkRequest &request, QIODevice *data);
141 QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data);
142 QNetworkReply *deleteResource(const QNetworkRequest &request);
143 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr);
144 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data);
145
146#if QT_CONFIG(http)
147 QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart);
148 QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart);
149 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart);
150#endif
151
152#if !defined(QT_NO_BEARERMANAGEMENT) // ### Qt6: Remove section
153 QT_DEPRECATED_VERSION_5_15 void setConfiguration(const QNetworkConfiguration &config);
154 QT_DEPRECATED_VERSION_5_15 QNetworkConfiguration configuration() const;
155 QT_DEPRECATED_VERSION_5_15 QNetworkConfiguration activeConfiguration() const;
156
157QT_WARNING_PUSH
158QT_WARNING_DISABLE_DEPRECATED
159 QT_DEPRECATED_VERSION_5_15 void setNetworkAccessible(NetworkAccessibility accessible);
160 QT_DEPRECATED_VERSION_5_15 NetworkAccessibility networkAccessible() const;
161QT_WARNING_POP
162#endif
163
164#ifndef QT_NO_SSL
165 void connectToHostEncrypted(const QString &hostName, quint16 port = 443,
166 const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration());
167 void connectToHostEncrypted(const QString &hostName, quint16 port,
168 const QSslConfiguration &sslConfiguration,
169 const QString &peerName);
170#endif
171 void connectToHost(const QString &hostName, quint16 port = 80);
172
173 void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
174 QNetworkRequest::RedirectPolicy redirectPolicy() const;
175
176 bool autoDeleteReplies() const;
177 void setAutoDeleteReplies(bool autoDelete);
178
179 int transferTimeout() const;
180 void setTransferTimeout(int timeout = QNetworkRequest::DefaultTransferTimeoutConstant);
181
182Q_SIGNALS:
183#ifndef QT_NO_NETWORKPROXY
184 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
185#endif
186 void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
187 void finished(QNetworkReply *reply);
188#ifndef QT_NO_SSL
189 void encrypted(QNetworkReply *reply);
190 void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
191 void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator);
192#endif
193
194#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
195 QT_DEPRECATED_VERSION_5_15 void networkSessionConnected();
196
197#ifndef Q_MOC_RUN // moc has trouble with the expansion of these macros
198QT_WARNING_PUSH
199QT_WARNING_DISABLE_DEPRECATED
200#endif
201 QT_DEPRECATED_VERSION_5_15 void networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible);
202#ifndef Q_MOC_RUN // moc has trouble with the expansion of these macros
203QT_WARNING_POP
204#endif
205#endif
206
207protected:
208 virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
209 QIODevice *outgoingData = nullptr);
210
211protected Q_SLOTS:
212 QStringList supportedSchemesImplementation() const;
213
214private:
215 friend class QNetworkReplyImplPrivate;
216 friend class QNetworkReplyHttpImpl;
217 friend class QNetworkReplyHttpImplPrivate;
218 friend class QNetworkReplyFileImpl;
219
220#ifdef Q_OS_WASM
221 friend class QNetworkReplyWasmImpl;
222#endif
223 Q_DECLARE_PRIVATE(QNetworkAccessManager)
224 Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
225 Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
226#ifndef QT_NO_BEARERMANAGEMENT // ### Qt6: Remove section
227 Q_PRIVATE_SLOT(d_func(), void _q_networkSessionClosed())
228 Q_PRIVATE_SLOT(d_func(), void _q_networkSessionStateChanged(QNetworkSession::State))
229 Q_PRIVATE_SLOT(d_func(), void _q_configurationChanged(const QNetworkConfiguration &))
230 Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed(QNetworkSession::SessionError))
231#endif
232 Q_PRIVATE_SLOT(d_func(), void _q_onlineStateChanged(bool))
233};
234
235QT_END_NAMESPACE
236
237#endif
238

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