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

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