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
4#ifndef QNETWORKACCESSMANAGER_H
5#define QNETWORKACCESSMANAGER_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtNetwork/qnetworkrequest.h>
9#include <QtCore/QString>
10#include <QtCore/QList>
11#include <QtCore/QObject>
12#ifndef QT_NO_SSL
13#include <QtNetwork/QSslConfiguration>
14#include <QtNetwork/QSslPreSharedKeyAuthenticator>
15#endif
16Q_MOC_INCLUDE(<QtNetwork/QSslError>)
17
18QT_BEGIN_NAMESPACE
19
20class QIODevice;
21class QAbstractNetworkCache;
22class QAuthenticator;
23class QByteArray;
24class QNetworkCookie;
25class QNetworkCookieJar;
26class QNetworkReply;
27class QNetworkProxy;
28class QNetworkProxyFactory;
29class QSslError;
30class QHstsPolicy;
31class QHttpMultiPart;
32
33class QNetworkReplyImplPrivate;
34class QNetworkAccessManagerPrivate;
35class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
36{
37 Q_OBJECT
38
39
40public:
41 enum Operation {
42 HeadOperation = 1,
43 GetOperation,
44 PutOperation,
45 PostOperation,
46 DeleteOperation,
47 CustomOperation,
48
49 UnknownOperation = 0
50 };
51
52 explicit QNetworkAccessManager(QObject *parent = nullptr);
53 ~QNetworkAccessManager();
54
55 virtual QStringList supportedSchemes() const;
56
57 void clearAccessCache();
58
59 void clearConnectionCache();
60
61#ifndef QT_NO_NETWORKPROXY
62 QNetworkProxy proxy() const;
63 void setProxy(const QNetworkProxy &proxy);
64 QNetworkProxyFactory *proxyFactory() const;
65 void setProxyFactory(QNetworkProxyFactory *factory);
66#endif
67
68 QAbstractNetworkCache *cache() const;
69 void setCache(QAbstractNetworkCache *cache);
70
71 QNetworkCookieJar *cookieJar() const;
72 void setCookieJar(QNetworkCookieJar *cookieJar);
73
74 void setStrictTransportSecurityEnabled(bool enabled);
75 bool isStrictTransportSecurityEnabled() const;
76 void enableStrictTransportSecurityStore(bool enabled, const QString &storeDir = QString());
77 bool isStrictTransportSecurityStoreEnabled() const;
78 void addStrictTransportSecurityHosts(const QList<QHstsPolicy> &knownHosts);
79 QList<QHstsPolicy> strictTransportSecurityHosts() const;
80
81 QNetworkReply *head(const QNetworkRequest &request);
82 QNetworkReply *get(const QNetworkRequest &request);
83 QNetworkReply *post(const QNetworkRequest &request, QIODevice *data);
84 QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data);
85 QNetworkReply *put(const QNetworkRequest &request, QIODevice *data);
86 QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data);
87 QNetworkReply *deleteResource(const QNetworkRequest &request);
88 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr);
89 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data);
90
91#if QT_CONFIG(http) || defined(Q_OS_WASM)
92 QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart);
93 QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart);
94 QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart);
95#endif
96
97#ifndef QT_NO_SSL
98 void connectToHostEncrypted(const QString &hostName, quint16 port = 443,
99 const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration());
100 void connectToHostEncrypted(const QString &hostName, quint16 port,
101 const QSslConfiguration &sslConfiguration,
102 const QString &peerName);
103#endif
104 void connectToHost(const QString &hostName, quint16 port = 80);
105
106 void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy);
107 QNetworkRequest::RedirectPolicy redirectPolicy() const;
108
109 bool autoDeleteReplies() const;
110 void setAutoDeleteReplies(bool autoDelete);
111
112 int transferTimeout() const;
113 void setTransferTimeout(int timeout = QNetworkRequest::DefaultTransferTimeoutConstant);
114
115Q_SIGNALS:
116#ifndef QT_NO_NETWORKPROXY
117 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator);
118#endif
119 void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator);
120 void finished(QNetworkReply *reply);
121#ifndef QT_NO_SSL
122 void encrypted(QNetworkReply *reply);
123 void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
124 void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator);
125#endif
126
127protected:
128 virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request,
129 QIODevice *outgoingData = nullptr);
130
131protected Q_SLOTS:
132 QStringList supportedSchemesImplementation() const;
133
134private:
135 friend class QNetworkReplyImplPrivate;
136 friend class QNetworkReplyHttpImpl;
137 friend class QNetworkReplyHttpImplPrivate;
138 friend class QNetworkReplyFileImpl;
139
140#ifdef Q_OS_WASM
141 friend class QNetworkReplyWasmImpl;
142#endif
143 Q_DECLARE_PRIVATE(QNetworkAccessManager)
144 Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>))
145#ifndef QT_NO_SSL
146 Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))
147#endif
148};
149
150QT_END_NAMESPACE
151
152#endif
153

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