4#include <QtNetwork/private/qtnetworkglobal_p.h>
17#if QT_CONFIG(settings)
30#include "QtCore/qbuffer.h"
31#include "QtCore/qlist.h"
32#include "QtCore/qurl.h"
33#include "QtNetwork/private/qauthenticator_p.h"
34#include "QtNetwork/qsslconfiguration.h"
37#include "QtNetwork/private/http2protocol_p.h"
47#include "QtCore/qapplicationstatic.h"
48#include "QtCore/qloggingcategory.h"
49#include <QtCore/private/qfactoryloader_p.h>
51#if defined(Q_OS_MACOS)
52#include <QtCore/private/qcore_mac_p.h>
54#include <CoreServices/CoreServices.h>
55#include <SystemConfiguration/SystemConfiguration.h>
56#include <Security/Security.h>
76#ifdef QT_BUILD_INTERNAL
82#if defined(Q_OS_MACOS)
85 CFStringRef protocolType =
nullptr;
87 protocolType = kSecAttrProtocolFTPProxy;
90 protocolType = kSecAttrProtocolHTTPProxy;
93 protocolType = kSecAttrProtocolHTTPSProxy;
95 qCWarning(lcQnam) <<
"Cannot query user name and password for a proxy, unnknown protocol:"
101 0,
nullptr,
nullptr));
104 CFDictionaryAddValue(
query, kSecClass, kSecClassInternetPassword);
105 CFDictionaryAddValue(
query, kSecAttrProtocol, protocolType);
108 if (proxyHostname.
size()) {
109 serverName = proxyHostname.toCFString();
110 CFDictionaryAddValue(
query, kSecAttrServer, serverName);
114 CFDictionaryAddValue(
query, kSecReturnAttributes, kCFBooleanTrue);
116 CFDictionaryAddValue(
query, kSecReturnData, kCFBooleanTrue);
122 if (SecItemCopyMatching(
query, &replyData) != errSecSuccess) {
123 qCWarning(lcQnam,
"Failed to extract user name and password from the keychain.");
127 if (!replyData || CFDictionaryGetTypeID() != CFGetTypeID(replyData)) {
128 qCWarning(lcQnam,
"Query returned data in unexpected format.");
132 CFDictionaryRef accountData = replyData.
as<CFDictionaryRef>();
133 const void *
value = CFDictionaryGetValue(accountData, kSecAttrAccount);
134 if (!
value || CFGetTypeID(
value) != CFStringGetTypeID()) {
135 qCWarning(lcQnam,
"Cannot find user name or its format is unknown.");
138 username = QString::fromCFString(
static_cast<CFStringRef
>(
value));
140 value = CFDictionaryGetValue(accountData, kSecValueData);
141 if (!
value || CFGetTypeID(
value) != CFDataGetTypeID()) {
142 qCWarning(lcQnam,
"Cannot find password or its format is unknown.");
145 const CFDataRef passData =
static_cast<const CFDataRef
>(
value);
156#ifdef QT_BUILD_INTERNAL
157 (
void) debugpipeBackend();
161 (
void) fileBackend();
399 d_func()->ensureBackendPluginsLoaded();
401 qRegisterMetaType<QNetworkReply::NetworkError>();
402#ifndef QT_NO_NETWORKPROXY
403 qRegisterMetaType<QNetworkProxy>();
406 qRegisterMetaType<QList<QSslError> >();
407 qRegisterMetaType<QSslConfiguration>();
408 qRegisterMetaType<QSslPreSharedKeyAuthenticator *>();
410 qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >();
412 qRegisterMetaType<QHttpNetworkRequest>();
414 qRegisterMetaType<QNetworkReply::NetworkError>();
415 qRegisterMetaType<QSharedPointer<char> >();
427#ifndef QT_NO_NETWORKPROXY
428 delete d_func()->proxyFactory;
441#ifndef QT_NO_NETWORKPROXY
451 return d_func()->proxy;
471 delete d->proxyFactory;
473 d->proxyFactory =
nullptr;
490 return d_func()->proxyFactory;
525 delete d->proxyFactory;
541 return d->networkCache;
563 if (
d->networkCache !=
cache) {
564 delete d->networkCache;
567 d->networkCache->setParent(
this);
582 d->createCookieJar();
618 d->cookieJarCreated =
true;
620 if (
d->cookieJar &&
d->cookieJar->parent() ==
this)
624 d->cookieJar->setParent(
this);
660 return d->stsEnabled;
685#if QT_CONFIG(settings)
688 d->stsCache.setStore(
d->stsStore.data());
692 qWarning(
"HSTS permanent store requires the feature 'settings' enabled");
707#if QT_CONFIG(settings)
709 return bool(
d->stsStore.data());
738 d->stsCache.updateFromPolicies(knownHosts);
753 return d->stsCache.policies();
818#if QT_CONFIG(http) || defined(Q_OS_WASM)
1037 return d->redirectPolicy;
1085#if QT_CONFIG(http) || defined(Q_OS_WASM)
1134#if QT_CONFIG(http) || defined (Q_OS_WASM)
1135 if (!req.transferTimeout())
1154 || scheme ==
"assets"_L1
1156 || scheme ==
"qrc"_L1) {
1160 if (scheme ==
"data"_L1)
1172 priv->manager =
this;
1174 priv->backend->setManagerPrivate(this->d_func());
1176 priv->backend->setReplyPrivate(
priv);
1177 priv->setup(op, req, outgoingData);
1202 if (scheme ==
"http"_L1 || scheme ==
"https"_L1 || scheme.
isEmpty()) {
1205 priv->manager =
this;
1212 constexpr char16_t httpSchemes[][17] = {
1217 u
"preconnect-https",
1221 if (std::find(std::begin(httpSchemes), std::end(httpSchemes), scheme) != std::end(httpSchemes)) {
1234 if (stsUrl.
port() == 80)
1248 priv->manager =
this;
1257 if (
priv->backend) {
1259 priv->backend->setReplyPrivate(
priv);
1287 schemes.removeDuplicates();
1364 return d_func()->autoDeleteReplies;
1383 d_func()->autoDeleteReplies = shouldAutoDelete;
1396 return d_func()->transferTimeout;
1418 d_func()->transferTimeout =
timeout;
1458 emit q->preSharedKeyAuthenticationRequired(
reply, authenticator);
1471 q->connect(
reply, &QNetworkReply::encrypted,
reply,
1494 QUrl *urlForLastAuthentication,
1495 bool allowAuthenticationReuse)
1502 if (allowAuthenticationReuse && (urlForLastAuthentication->
isEmpty()
1503 ||
url != *urlForLastAuthentication)) {
1510 *urlForLastAuthentication =
url;
1520 *urlForLastAuthentication =
url;
1530 *urlForLastAuthentication =
url;
1531 emit q->authenticationRequired(
reply, authenticator);
1532 if (allowAuthenticationReuse)
1536#ifndef QT_NO_NETWORKPROXY
1545 if (
proxy != *lastProxyAuthentication && (!
priv || !
priv->hasFailed)) {
1554#if defined(Q_OS_MACOS)
1563 if (!
priv->hasFailed || cred.
user != username || cred.
password != password) {
1564 authenticator->
setUser(username);
1579 *lastProxyAuthentication =
proxy;
1580 emit q->proxyAuthenticationRequired(
proxy, authenticator);
1590 qWarning(
"QNetworkAccessManager: factory %p has returned an empty result set",
1607 manager->d_func()->authenticationManager->clearCache();
1612 manager->d_func()->objectCache.clear();
1613 manager->d_func()->destroyThread();
1646#if QT_CONFIG(http) || defined(Q_OS_WASM)
1657 contentType +=
"multipart/";
1658 switch (
multiPart->d_func()->contentType) {
1660 contentType +=
"related";
1663 contentType +=
"form-data";
1666 contentType +=
"alternative";
1669 contentType +=
"mixed";
1684 if (!
device->isReadable()) {
1687 qWarning(
"could not open device for reading");
1689 qWarning(
"device is not readable");
1705 std::unique_lock locker(
mutex);
1708#if QT_CONFIG(library)
1709 qnabfLoader->update();
1712 while (qnabfLoader->instance(
index))
1718#include "moc_qnetworkaccessmanager.cpp"
IOBluetoothDevice * device
The QAbstractNetworkCache class provides the interface for cache implementations.
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
The QAuthenticator class provides an authentication object.
QString user() const
Returns the user used for authentication.
void setPassword(const QString &password)
Sets the password used for authentication.
QString password() const
Returns the password used for authentication.
void setUser(const QString &user)
Sets the user used for authentication.
\inmodule QtCore \reentrant
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
void reserve(qsizetype size)
Attempts to allocate memory for at least size bytes.
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP.
QByteArray boundary() const
returns the boundary.
\inmodule QtCore \reentrant
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
bool isEmpty() const noexcept
QList< QNetworkProxy > queryProxy(const QNetworkProxyQuery &query)
QNetworkReply * postProcess(QNetworkReply *reply)
QNetworkProxyFactory * proxyFactory
void proxyAuthenticationRequired(const QUrl &url, const QNetworkProxy &proxy, bool synchronous, QAuthenticator *authenticator, QNetworkProxy *lastProxyAuthentication)
void _q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator)
void createCookieJar() const
void ensureBackendPluginsLoaded()
void authenticationRequired(QAuthenticator *authenticator, QNetworkReply *reply, bool synchronous, QUrl &url, QUrl *urlForLastAuthentication, bool allowAuthenticationReuse=true)
QNetworkCookieJar * cookieJar
std::shared_ptr< QNetworkAccessAuthenticationManager > authenticationManager
~QNetworkAccessManagerPrivate()
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)
The QNetworkAccessManager class allows the application to send network requests and receive replies.
friend class QNetworkReplyHttpImpl
void setCookieJar(QNetworkCookieJar *cookieJar)
Sets the manager's cookie jar to be the cookieJar specified.
QNetworkReply * put(const QNetworkRequest &request, QIODevice *data)
Uploads the contents of data to the destination request and returns a new QNetworkReply object that w...
void connectToHost(const QString &hostName, quint16 port=80)
~QNetworkAccessManager()
Destroys the QNetworkAccessManager object and frees up any resources.
QNetworkReply * head(const QNetworkRequest &request)
Posts a request to obtain the network headers for request and returns a new QNetworkReply object whic...
bool isStrictTransportSecurityStoreEnabled() const
QList< QHstsPolicy > strictTransportSecurityHosts() const
virtual QStringList supportedSchemes() const
QNetworkRequest::RedirectPolicy redirectPolicy() const
QNetworkReply * post(const QNetworkRequest &request, QIODevice *data)
Sends an HTTP POST request to the destination specified by request and returns a new QNetworkReply ob...
void setProxy(const QNetworkProxy &proxy)
Sets the proxy to be used in future requests to be proxy.
QStringList supportedSchemesImplementation() const
void setAutoDeleteReplies(bool autoDelete)
bool isStrictTransportSecurityEnabled() const
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy)
QNetworkReply * sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data=nullptr)
QNetworkProxy proxy() const
Returns the QNetworkProxy that the requests sent using this QNetworkAccessManager object will use.
virtual QNetworkReply * createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData=nullptr)
Returns a new QNetworkReply object to handle the operation op and request originalReq.
void setStrictTransportSecurityEnabled(bool enabled)
void clearConnectionCache()
QAbstractNetworkCache * cache() const
friend class QNetworkReplyFileImpl
int transferTimeout() const
void addStrictTransportSecurityHosts(const QList< QHstsPolicy > &knownHosts)
Operation
Indicates the operation this reply is processing.
void setTransferTimeout(int timeout=QNetworkRequest::DefaultTransferTimeoutConstant)
QNetworkReply * deleteResource(const QNetworkRequest &request)
bool autoDeleteReplies() const
void connectToHostEncrypted(const QString &hostName, quint16 port=443, const QSslConfiguration &sslConfiguration=QSslConfiguration::defaultConfiguration())
void setProxyFactory(QNetworkProxyFactory *factory)
QNetworkProxyFactory * proxyFactory() const
void setCache(QAbstractNetworkCache *cache)
QNetworkCookieJar * cookieJar() const
Returns the QNetworkCookieJar that is used to store cookies obtained from the network as well as cook...
void enableStrictTransportSecurityStore(bool enabled, const QString &storeDir=QString())
QNetworkAccessManager(QObject *parent=nullptr)
Constructs a QNetworkAccessManager object that is the center of the Network Access API and sets paren...
The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects.
The QNetworkProxyFactory class provides fine-grained proxy selection.
virtual QList< QNetworkProxy > queryProxy(const QNetworkProxyQuery &query=QNetworkProxyQuery())=0
This function takes the query request, query, examines the details of the type of socket or request a...
static QList< QNetworkProxy > proxyForQuery(const QNetworkProxyQuery &query)
This function takes the query request, query, examines the details of the type of socket or request a...
The QNetworkProxyQuery class is used to query the proxy settings for a socket.
The QNetworkProxy class provides a network layer proxy.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
QString hostName() const
Returns the host name of the proxy host.
static void setManager(QNetworkReply *reply, QNetworkAccessManager *manager)
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
void finished()
This signal is emitted when the reply has finished processing.
QNetworkRequest request() const
Returns the request that was posted for this reply.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
void setSslConfiguration(const QSslConfiguration &configuration)
Sets this network request's SSL configuration to be config.
@ CookieLoadControlAttribute
@ AutoDeleteReplyOnFinishAttribute
@ CacheLoadControlAttribute
@ RedirectPolicyAttribute
void setHeader(KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers.
void setAttribute(Attribute code, const QVariant &value)
Sets the attribute associated with code code to be value value.
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
@ NoLessSafeRedirectPolicy
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
void setRawHeader(const QByteArray &headerName, const QByteArray &value)
Sets the header headerName to be of value headerValue.
void setPeerVerifyName(const QString &peerName)
bool hasRawHeader(const QByteArray &headerName) const
Returns true if the raw header headerName is present in this network request.
void setUrl(const QUrl &url)
Sets the URL this network request is referring to be url.
QUrl url() const
Returns the URL this network request is referring to.
CacheLoadControl
Controls the caching mechanism of QNetworkAccessManager.
QSslConfiguration sslConfiguration() const
Returns this network request's SSL configuration.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QThread * thread() const
Returns the thread in which the object lives.
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
void deleteLater()
\threadsafe
The QSslConfiguration class holds the configuration and state of an SSL connection.
QList< QByteArray > allowedNextProtocols() const
static const char ALPNProtocolHTTP2[]
static QSslConfiguration defaultConfiguration()
Returns the default SSL configuration to be used in new SSL connections.
The QSslPreSharedKeyAuthenticator class provides authentication data for pre shared keys (PSK) cipher...
static bool supportsSsl()
Returns true if this platform supports SSL; otherwise, returns false.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLocal8Bit(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
int compare(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
void start(Priority=InheritPriority)
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
QString userName(ComponentFormattingOptions options=FullyDecoded) const
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
QString password(ComponentFormattingOptions=FullyDecoded) const
Returns the password of the URL if it is defined; otherwise an empty string is returned.
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
QString scheme() const
Returns the scheme of the URL.
void setScheme(const QString &scheme)
Sets the scheme of the URL to scheme.
void setHost(const QString &host, ParsingMode mode=DecodedMode)
Sets the host of the URL to host.
int port(int defaultPort=-1) const
void setPort(int port)
Sets the port of the URL to port.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
bool isNull() const
Returns true if this is a null variant, false otherwise.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
qDeleteAll(list.begin(), list.end())
QCache< int, Employee > cache
[0]
Combined button and popup list for selecting options.
#define Q_APPLICATION_STATIC(TYPE, NAME,...)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define QNetworkAccessBackendFactory_iid
static void ensureInitialized()
#define Q_RETURN_ARG(Type, data)
GLbitfield GLuint64 timeout
[4]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
#define QStringLiteral(str)
QUrl url("example.com")
[constructor-url-reference]
QItemEditorFactory * factory
QNetworkAccessManager manager
QHttpMultiPart * multiPart
[0]
QNetworkRequest request(url)
bool contains(const AT &t) const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent