Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnetworkaccessbackend_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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// Qt-Security score:significant reason:default
4
5#ifndef QNETWORKACCESSBACKEND_P_H
6#define QNETWORKACCESSBACKEND_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/qtnetworkglobal.h>
20
21#include <QtNetwork/qnetworkrequest.h>
22#include <QtNetwork/qnetworkaccessmanager.h>
23#include <QtNetwork/qnetworkreply.h>
24
25#include <QtCore/qobject.h>
26#include <QtCore/qflags.h>
27#include <QtCore/qbytearrayview.h>
28#if QT_CONFIG(ssl)
29#include <QtNetwork/qsslconfiguration.h>
30#endif
31
33
37class Q_NETWORK_EXPORT QNetworkAccessBackend : public QObject
38{
39 Q_OBJECT
40 Q_DECLARE_PRIVATE(QNetworkAccessBackend);
41
42public:
43 enum class TargetType {
44 Networked = 0x1, // We need to query for proxy in case it is needed
45 Local = 0x2, // Local file, generated data or local device
46 };
47 Q_ENUM(TargetType)
48 Q_DECLARE_FLAGS(TargetTypes, TargetType)
49
50 enum class SecurityFeature {
51 None = 0x0,
52 TLS = 0x1, // We need to set QSslConfiguration
53 };
54 Q_ENUM(SecurityFeature)
55 Q_DECLARE_FLAGS(SecurityFeatures, SecurityFeature)
56
57 enum class IOFeature {
58 None = 0x0,
59 ZeroCopy = 0x1, // readPointer and advanceReadPointer() is available!
60 NeedResetableUpload = 0x2, // Need to buffer upload data
61 SupportsSynchronousMode = 0x4, // Used for XMLHttpRequest
62 };
63 Q_ENUM(IOFeature)
64 Q_DECLARE_FLAGS(IOFeatures, IOFeature)
65
66 QNetworkAccessBackend(TargetTypes targetTypes, SecurityFeatures securityFeatures,
67 IOFeatures ioFeatures);
68 QNetworkAccessBackend(TargetTypes targetTypes);
69 QNetworkAccessBackend(TargetTypes targetTypes, SecurityFeatures securityFeatures);
70 QNetworkAccessBackend(TargetTypes targetTypes, IOFeatures ioFeatures);
71 virtual ~QNetworkAccessBackend();
72
73 SecurityFeatures securityFeatures() const noexcept;
74 TargetTypes targetTypes() const noexcept;
75 IOFeatures ioFeatures() const noexcept;
76
77 inline bool needsResetableUploadData() const noexcept
78 {
79 return ioFeatures() & IOFeature::NeedResetableUpload;
80 }
81
82 virtual bool start();
83 virtual void open() = 0;
84 virtual void close() = 0;
85#if QT_CONFIG(ssl)
86 virtual void setSslConfiguration(const QSslConfiguration &configuration);
87 virtual QSslConfiguration sslConfiguration() const;
88#endif
89 virtual void ignoreSslErrors();
90 virtual void ignoreSslErrors(const QList<QSslError> &errors);
91 virtual qint64 bytesAvailable() const = 0;
92 virtual QByteArrayView readPointer();
93 virtual void advanceReadPointer(qint64 distance);
94 virtual qint64 read(char *data, qint64 maxlen);
95 virtual bool wantToRead();
96
97#if QT_CONFIG(networkproxy)
98 QList<QNetworkProxy> proxyList() const;
99#endif
100 QUrl url() const;
101 void setUrl(const QUrl &url);
102 QVariant header(QNetworkRequest::KnownHeaders header) const;
103 void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value);
104 QByteArray rawHeader(const QByteArray &header) const;
105 void setRawHeader(const QByteArray &header, const QByteArray &value);
106 QHttpHeaders headers() const;
107 void setHeaders(const QHttpHeaders &newHeaders);
108 void setHeaders(QHttpHeaders &&newHeaders);
109 QNetworkAccessManager::Operation operation() const;
110
111 bool isCachingEnabled() const;
112 void setCachingEnabled(bool canCache);
113
114 void setAttribute(QNetworkRequest::Attribute attribute, const QVariant &value);
115
116 QIODevice *createUploadByteDevice();
117 QIODevice *uploadByteDevice();
118
119 QAbstractNetworkCache *networkCache() const;
120
121public slots:
122 void readyRead();
123protected slots:
124 void finished();
125 void error(QNetworkReply::NetworkError code, const QString &errorString);
126#ifndef QT_NO_NETWORKPROXY
127 void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *auth);
128#endif
129 void authenticationRequired(QAuthenticator *auth);
130 void metaDataChanged();
131 void redirectionRequested(const QUrl &destination);
132
133private:
134 void setReplyPrivate(QNetworkReplyImplPrivate *reply);
135 void setManagerPrivate(QNetworkAccessManagerPrivate *manager);
136 bool isSynchronous() const;
137 void setSynchronous(bool synchronous);
138
139 friend class QNetworkAccessManager; // for setReplyPrivate
140 friend class QNetworkAccessManagerPrivate; // for setManagerPrivate
141 friend class QNetworkReplyImplPrivate; // for {set,is}Synchronous()
142};
143
144class Q_NETWORK_EXPORT QNetworkAccessBackendFactory : public QObject
145{
146 Q_OBJECT
147public:
148 QNetworkAccessBackendFactory();
149 virtual ~QNetworkAccessBackendFactory();
150 virtual QStringList supportedSchemes() const = 0;
151 virtual QNetworkAccessBackend *create(QNetworkAccessManager::Operation op,
152 const QNetworkRequest &request) const = 0;
153};
154
155#define QNetworkAccessBackendFactory_iid "org.qt-project.Qt.NetworkAccessBackendFactory"
157
158QT_END_NAMESPACE
159#endif
void cacheCredentials(const QUrl &url, const QAuthenticator *auth)
QNetworkAuthenticationCredential fetchCachedCredentials(const QUrl &url, const QAuthenticator *auth=nullptr)
Fetch the credential data from the credential cache.
QNetworkAuthenticationCredential fetchCachedProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth=nullptr)
void cacheProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth)
QNetworkAccessBackend is the base class for implementing support for schemes used by QNetworkAccessMa...
QNetworkRequest::RedirectPolicy redirectPolicy
QNetworkAuthenticationCredential * fetchCachedCredentials(const QUrl &url, const QAuthenticator *auth=nullptr)
QStringList backendSupportedSchemes() const
QList< QNetworkProxy > queryProxy(const QNetworkProxyQuery &query)
QNetworkReply * postProcess(QNetworkReply *reply)
QNetworkAccessBackend * findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request)
void proxyAuthenticationRequired(const QUrl &url, const QNetworkProxy &proxy, bool synchronous, QAuthenticator *authenticator, QNetworkProxy *lastProxyAuthentication)
void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator)
std::chrono::milliseconds transferTimeout
void authenticationRequired(QAuthenticator *authenticator, QNetworkReply *reply, bool synchronous, QUrl &url, QUrl *urlForLastAuthentication, bool allowAuthenticationReuse=true)
void cacheProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth)
std::shared_ptr< QNetworkAccessAuthenticationManager > authenticationManager
void cacheCredentials(const QUrl &url, const QAuthenticator *auth)
QNetworkAuthenticationCredential * fetchCachedProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth=nullptr)
void _q_replyFinished(QNetworkReply *reply)
void _q_replyEncrypted(QNetworkReply *reply)
void _q_replySslErrors(const QList< QSslError > &errors)
static Q_AUTOTEST_EXPORT void clearConnectionCache(QNetworkAccessManager *manager)
static Q_AUTOTEST_EXPORT void clearAuthenticationCache(QNetworkAccessManager *manager)
iterator findClosestMatch(const QString &domain)
void insert(const QString &domain, const QString &user, const QString &password)
static QByteArray proxyAuthenticationKey(const QNetworkProxy &proxy, const QString &realm)
static QByteArray authenticationKey(const QUrl &url, const QString &realm)
#define QNetworkAccessBackendFactory_iid
Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid)