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_P_H |
41 | #define QNETWORKACCESSMANAGER_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists for the convenience |
48 | // of the Network Access API. This header file may change from |
49 | // version to version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtNetwork/private/qtnetworkglobal_p.h> |
55 | #include "qnetworkaccessmanager.h" |
56 | #include "qnetworkaccesscache_p.h" |
57 | #include "qnetworkaccessbackend_p.h" |
58 | #include "private/qnetconmonitor_p.h" |
59 | #include "qnetworkrequest.h" |
60 | #include "qhsts_p.h" |
61 | #include "private/qobject_p.h" |
62 | #include "QtNetwork/qnetworkproxy.h" |
63 | #include "qnetworkaccessauthenticationmanager_p.h" |
64 | |
65 | #if QT_CONFIG(settings) |
66 | #include "qhstsstore_p.h" |
67 | #endif // QT_CONFIG(settings) |
68 | |
69 | QT_BEGIN_NAMESPACE |
70 | |
71 | class QAuthenticator; |
72 | class QAbstractNetworkCache; |
73 | class QNetworkAuthenticationCredential; |
74 | class QNetworkCookieJar; |
75 | |
76 | class QNetworkAccessManagerPrivate: public QObjectPrivate |
77 | { |
78 | public: |
79 | QNetworkAccessManagerPrivate() |
80 | : networkCache(nullptr), |
81 | cookieJar(nullptr), |
82 | thread(nullptr), |
83 | #ifndef QT_NO_NETWORKPROXY |
84 | proxyFactory(nullptr), |
85 | #endif |
86 | cookieJarCreated(false), |
87 | defaultAccessControl(true), |
88 | redirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy), |
89 | authenticationManager(QSharedPointer<QNetworkAccessAuthenticationManager>::create()) |
90 | { |
91 | } |
92 | ~QNetworkAccessManagerPrivate(); |
93 | |
94 | QThread * createThread(); |
95 | void destroyThread(); |
96 | |
97 | void _q_replyFinished(QNetworkReply *reply); |
98 | void _q_replyEncrypted(QNetworkReply *reply); |
99 | void _q_replySslErrors(const QList<QSslError> &errors); |
100 | void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator); |
101 | QNetworkReply *postProcess(QNetworkReply *reply); |
102 | void createCookieJar() const; |
103 | |
104 | void authenticationRequired(QAuthenticator *authenticator, |
105 | QNetworkReply *reply, |
106 | bool synchronous, |
107 | QUrl &url, |
108 | QUrl *urlForLastAuthentication, |
109 | bool allowAuthenticationReuse = true); |
110 | void cacheCredentials(const QUrl &url, const QAuthenticator *auth); |
111 | QNetworkAuthenticationCredential *fetchCachedCredentials(const QUrl &url, |
112 | const QAuthenticator *auth = nullptr); |
113 | |
114 | #ifndef QT_NO_NETWORKPROXY |
115 | void proxyAuthenticationRequired(const QUrl &url, |
116 | const QNetworkProxy &proxy, |
117 | bool synchronous, |
118 | QAuthenticator *authenticator, |
119 | QNetworkProxy *lastProxyAuthentication); |
120 | void cacheProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth); |
121 | QNetworkAuthenticationCredential *fetchCachedProxyCredentials(const QNetworkProxy &proxy, |
122 | const QAuthenticator *auth = nullptr); |
123 | QList<QNetworkProxy> queryProxy(const QNetworkProxyQuery &query); |
124 | #endif |
125 | |
126 | QNetworkAccessBackend *findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request); |
127 | QStringList backendSupportedSchemes() const; |
128 | |
129 | #if QT_CONFIG(http) || defined(Q_OS_WASM) |
130 | QNetworkRequest prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart); |
131 | #endif |
132 | |
133 | void ensureBackendPluginsLoaded(); |
134 | |
135 | // this is the cache for storing downloaded files |
136 | QAbstractNetworkCache *networkCache; |
137 | |
138 | QNetworkCookieJar *cookieJar; |
139 | |
140 | QThread *thread; |
141 | |
142 | |
143 | #ifndef QT_NO_NETWORKPROXY |
144 | QNetworkProxy proxy; |
145 | QNetworkProxyFactory *proxyFactory; |
146 | #endif |
147 | |
148 | bool cookieJarCreated; |
149 | bool defaultAccessControl; |
150 | QNetworkRequest::RedirectPolicy redirectPolicy = QNetworkRequest::NoLessSafeRedirectPolicy; |
151 | |
152 | // The cache with authorization data: |
153 | QSharedPointer<QNetworkAccessAuthenticationManager> authenticationManager; |
154 | |
155 | // this cache can be used by individual backends to cache e.g. their TCP connections to a server |
156 | // and use the connections for multiple requests. |
157 | QNetworkAccessCache objectCache; |
158 | |
159 | Q_AUTOTEST_EXPORT static void clearAuthenticationCache(QNetworkAccessManager *manager); |
160 | Q_AUTOTEST_EXPORT static void clearConnectionCache(QNetworkAccessManager *manager); |
161 | |
162 | QHstsCache stsCache; |
163 | #if QT_CONFIG(settings) |
164 | QScopedPointer<QHstsStore> stsStore; |
165 | #endif // QT_CONFIG(settings) |
166 | bool stsEnabled = false; |
167 | |
168 | bool autoDeleteReplies = false; |
169 | |
170 | int transferTimeout = 0; |
171 | |
172 | Q_DECLARE_PUBLIC(QNetworkAccessManager) |
173 | }; |
174 | |
175 | QT_END_NAMESPACE |
176 | |
177 | #endif |
178 | |