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/QList>
47#include <QtCore/QObject>
48#ifndef QT_NO_SSL
49#include <QtNetwork/QSslConfiguration>
50#include <QtNetwork/QSslPreSharedKeyAuthenticator>
51#endif
52Q_MOC_INCLUDE(<QtNetwork/QSslError>)
53
54QT_BEGIN_NAMESPACE
55
56class QIODevice;
57class QAbstractNetworkCache;
58class QAuthenticator;
59class QByteArray;
60class QNetworkCookie;
61class QNetworkCookieJar;
62class QNetworkReply;
63class QNetworkProxy;
64class QNetworkProxyFactory;
65class QSslError;
66class QHstsPolicy;
67class QHttpMultiPart;
68
69class QNetworkReplyImplPrivate;
70class QNetworkAccessManagerPrivate;
71class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
72{
73 Q_OBJECT
74
75
76public:
77 enum Operation {
78 HeadOperation = 1,
79 GetOperation,
80 PutOperation,
81 PostOperation,
82 DeleteOperation,
83 CustomOperation,
84
85 UnknownOperation = 0
86 };
87
88 explicit QNetworkAccessManager(QObject *parent = nullptr);
89 ~QNetworkAccessManager();
90
91 virtual QStringList supportedSchemes() const;
92
93 void clearAccessCache();
94
95 void clearConnectionCache();
96
97#ifndef QT_NO_NETWORKPROXY
98 QNetworkProxy proxy() const;
99 void setProxy(const QNetworkProxy &proxy);
100 QNetworkProxyFactory *proxyFactory() const;
101 void setProxyFactory(QNetworkProxyFactory *factory);
102#endif
103
104 QAbstractNetworkCache *cache() const;
105 void setCache(QAbstractNetworkCache *cache);
106
107 QNetworkCookieJar *cookieJar() const;
108 void setCookieJar(QNetworkCookieJar *cookieJar);
109
110 void setStrictTransportSecurityEnabled(bool enabled);
111 bool isStrictTransportSecurityEnabled() const;
112 void enableStrictTransportSecurityStore(bool enabled, const QString &storeDir = QString());
113 bool isStrictTransportSecurityStoreEnabled() const;
114 void addStrictTransportSecurityHosts(const QList<QHstsPolicy> &knownHosts);
115 QList<QHstsPolicy> strictTransportSecurityHosts() const;
116
117 QNetworkReply *head(const QNetworkRequest &request);
118 QNetworkReply *get(const QNetworkRequest &request);
119 QNetworkReply *post(const QNetworkRequest &request, QIODevice *data);
120 QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data);
121 QNetworkReply *put(const QNetworkRequest &request, QIODevice *data);
122 QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data);
123 QNetworkReply *deleteResource(const QNetworkRequest &request);
124 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr);
125 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data);
126
127#if QT_CONFIG(http) || defined(Q_OS_WASM)
128 QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart);
129 QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart);
130 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart);
131#endif
132
133#ifndef QT_NO_SSL
134 void connectToHostEncrypted(const QString &hostName, quint16 port = 443,
135 const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration());
136 void connectToHostEncrypted(const QString &hostName, quint16 port,
137 const QSslConfiguration &sslConfiguration,
138 const QString &peerName);
139#endif
140 void connectToHost(const QString &hostName, quint16 port = 80);
141
142 void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
143 QNetworkRequest::RedirectPolicy redirectPolicy() const;
144
145 bool autoDeleteReplies() const;
146 void setAutoDeleteReplies(bool autoDelete);
147
148 int transferTimeout() const;
149 void setTransferTimeout(int timeout = QNetworkRequest::DefaultTransferTimeoutConstant);
150
151Q_SIGNALS:
152#ifndef QT_NO_NETWORKPROXY
153 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
154#endif
155 void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
156 void finished(QNetworkReply *reply);
157#ifndef QT_NO_SSL
158 void encrypted(QNetworkReply *reply);
159 void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
160 void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator);
161#endif
162
163protected:
164 virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
165 QIODevice *outgoingData = nullptr);
166
167protected Q_SLOTS:
168 QStringList supportedSchemesImplementation() const;
169
170private:
171 friend class QNetworkReplyImplPrivate;
172 friend class QNetworkReplyHttpImpl;
173 friend class QNetworkReplyHttpImplPrivate;
174 friend class QNetworkReplyFileImpl;
175
176#ifdef Q_OS_WASM
177 friend class QNetworkReplyWasmImpl;
178#endif
179 Q_DECLARE_PRIVATE(QNetworkAccessManager)
180 Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
181#ifndef QT_NO_SSL
182 Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
183#endif
184};
185
186QT_END_NAMESPACE
187
188#endif
189