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 |
16 | Q_MOC_INCLUDE(<QtNetwork/QSslError>) |
17 | |
18 | QT_BEGIN_NAMESPACE |
19 | |
20 | class QIODevice; |
21 | class QAbstractNetworkCache; |
22 | class QAuthenticator; |
23 | class QByteArray; |
24 | class QNetworkCookie; |
25 | class QNetworkCookieJar; |
26 | class QNetworkReply; |
27 | class QNetworkProxy; |
28 | class QNetworkProxyFactory; |
29 | class QSslError; |
30 | class QHstsPolicy; |
31 | class QHttpMultiPart; |
32 | |
33 | class QNetworkReplyImplPrivate; |
34 | class QNetworkAccessManagerPrivate; |
35 | class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject |
36 | { |
37 | Q_OBJECT |
38 | |
39 | |
40 | public: |
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 *(const QNetworkRequest &request); |
82 | QNetworkReply *get(const QNetworkRequest &request); |
83 | QNetworkReply *get(const QNetworkRequest &request, QIODevice *data); |
84 | QNetworkReply *get(const QNetworkRequest &request, const QByteArray &data); |
85 | QNetworkReply *post(const QNetworkRequest &request, QIODevice *data); |
86 | QNetworkReply *post(const QNetworkRequest &request, const QByteArray &data); |
87 | QNetworkReply *put(const QNetworkRequest &request, QIODevice *data); |
88 | QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data); |
89 | QNetworkReply *deleteResource(const QNetworkRequest &request); |
90 | QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr); |
91 | QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data); |
92 | |
93 | #if QT_CONFIG(http) || defined(Q_OS_WASM) |
94 | QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart); |
95 | QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart); |
96 | QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart); |
97 | #endif |
98 | |
99 | #ifndef QT_NO_SSL |
100 | void connectToHostEncrypted(const QString &hostName, quint16 port = 443, |
101 | const QSslConfiguration &sslConfiguration = QSslConfiguration::defaultConfiguration()); |
102 | void connectToHostEncrypted(const QString &hostName, quint16 port, |
103 | const QSslConfiguration &sslConfiguration, |
104 | const QString &peerName); |
105 | #endif |
106 | void connectToHost(const QString &hostName, quint16 port = 80); |
107 | |
108 | void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy); |
109 | QNetworkRequest::RedirectPolicy redirectPolicy() const; |
110 | |
111 | bool autoDeleteReplies() const; |
112 | void setAutoDeleteReplies(bool autoDelete); |
113 | |
114 | int transferTimeout() const; |
115 | void setTransferTimeout(int timeout); |
116 | |
117 | std::chrono::milliseconds transferTimeoutAsDuration() const; |
118 | void setTransferTimeout(std::chrono::milliseconds duration = |
119 | QNetworkRequest::DefaultTransferTimeout); |
120 | |
121 | Q_SIGNALS: |
122 | #ifndef QT_NO_NETWORKPROXY |
123 | void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator); |
124 | #endif |
125 | void authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator); |
126 | void finished(QNetworkReply *reply); |
127 | #ifndef QT_NO_SSL |
128 | void encrypted(QNetworkReply *reply); |
129 | void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors); |
130 | void preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator); |
131 | #endif |
132 | |
133 | protected: |
134 | virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &request, |
135 | QIODevice *outgoingData = nullptr); |
136 | |
137 | protected Q_SLOTS: |
138 | QStringList supportedSchemesImplementation() const; |
139 | |
140 | private: |
141 | friend class QNetworkReplyImplPrivate; |
142 | friend class QNetworkReplyHttpImpl; |
143 | friend class QNetworkReplyHttpImplPrivate; |
144 | friend class QNetworkReplyFileImpl; |
145 | |
146 | #ifdef Q_OS_WASM |
147 | friend class QNetworkReplyWasmImpl; |
148 | #endif |
149 | Q_DECLARE_PRIVATE(QNetworkAccessManager) |
150 | Q_PRIVATE_SLOT(d_func(), void _q_replySslErrors(QList<QSslError>)) |
151 | #ifndef QT_NO_SSL |
152 | Q_PRIVATE_SLOT(d_func(), void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)) |
153 | #endif |
154 | }; |
155 | |
156 | QT_END_NAMESPACE |
157 | |
158 | #endif |
159 | |