/*! Starts the backend. Returns \c true if the backend is started. Returns \c false if the backend could not be started due to an unopened or roaming session. The caller should recall this function once the session has been opened or the roaming process has finished. */ bool QNetworkAccessBackend::start() { #ifndef QT_NO_BEARERMANAGEMENT // For bearer, check if session start is required QSharedPointer<QNetworkSession> networkSession(manager->getNetworkSession()); if (networkSession) { // session required if (networkSession->isOpen() && networkSession->state() == QNetworkSession::Connected) { // Session is already open and ready to use. // copy network session down to the backend setProperty("_q_networksession", QVariant::fromValue(networkSession)); } else { // Session not ready, but can skip for loopback connections // This is not ideal. const QString host = reply->url.host(); if (host == QLatin1String("localhost") || QHostAddress(host).isLoopback() || reply->url.isLocalFile()) { // Don't need an open session for localhost access. } else { // need to wait for session to be opened return false; } } } #endif #ifndef QT_NO_NETWORKPROXY #ifndef QT_NO_BEARERMANAGEMENT // Get the proxy settings from the network session (in the case of service networks, // the proxy settings change depending which AP was activated) QNetworkSession *session = networkSession.data(); QNetworkConfiguration config; if (session) { QNetworkConfigurationManager configManager; // The active configuration tells us what IAP is in use QVariant v = session->sessionProperty(QLatin1String("ActiveConfiguration")); if (v.isValid()) config = configManager.configurationFromIdentifier(qvariant_cast<QString>(v)); // Fallback to using the configuration if no active configuration if (!config.isValid()) config = session->configuration(); // or unspecified configuration if that is no good either if (!config.isValid()) config = QNetworkConfiguration(); } reply->proxyList = manager->queryProxy(QNetworkProxyQuery(config, url())); #else // QT_NO_BEARERMANAGEMENT // Without bearer management, the proxy depends only on the url reply->proxyList = manager->queryProxy(QNetworkProxyQuery(url())); #endif #endif // now start the request open(); return true; }
/*! Returns the QNetworkConfiguration for \a identifier; otherwise returns an invalid QNetworkConfiguration. \sa QNetworkConfiguration::identifier() */ QNetworkConfiguration QNetworkConfigurationManager::configurationFromIdentifier(const QString &identifier) const { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); if (priv) return priv->configurationFromIdentifier(identifier); return QNetworkConfiguration(); }
/*! Returns the default configuration to be used. This function always returns a discovered configuration; otherwise an invalid configuration. In some cases it may be required to call updateConfigurations() and wait for the updateCompleted() signal before calling this function. \sa allConfigurations() */ QNetworkConfiguration QNetworkConfigurationManager::defaultConfiguration() const { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); if (priv) return priv->defaultConfiguration(); return QNetworkConfiguration(); }
/*! \since 4.7 Returns the network configuration that will be used to create the \l {QNetworkSession}{network session} which will be used when processing network requests. \sa setConfiguration(), activeConfiguration() */ QNetworkConfiguration QNetworkAccessManager::configuration() const { Q_D(const QNetworkAccessManager); if (d->networkSession) return d->networkSession->configuration(); else return QNetworkConfiguration(); }
/*! \since 4.7 Returns the current active network configuration. If the network configuration returned by configuration() is of type QNetworkConfiguration::ServiceNetwork this function will return the current active child network configuration of that configuration. Otherwise returns the same network configuration as configuration(). Use this function to return the actual network configuration currently in use by the network session. \sa configuration() */ QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const { Q_D(const QNetworkAccessManager); if (d->networkSession) { QNetworkConfigurationManager manager; return manager.configurationFromIdentifier( d->networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); } else { return QNetworkConfiguration(); } }
AccessManager::AccessManager(QObject *parent) : QNetworkAccessManager(parent) { #if defined(Q_OS_MAC) // FIXME Workaround http://stackoverflow.com/a/15707366/2941 https://bugreports.qt-project.org/browse/QTBUG-30434 QNetworkProxy proxy = this->proxy(); proxy.setHostName(" "); setProxy(proxy); #endif #ifndef Q_OS_LINUX // Atempt to workaround for https://github.com/owncloud/client/issues/3969 setConfiguration(QNetworkConfiguration()); #endif setCookieJar(new CookieJar); }
void RssFetcher::fetch(const QUrl &url) { QString agentStr = QString::fromLatin1("Qt-Creator/%1 (QHttp %2; %3; %4; %5 bit)") .arg(Core::Constants::IDE_VERSION_LONG).arg(qVersion()) .arg(getOsString()).arg(QLocale::system().name()) .arg(QSysInfo::WordSize); QNetworkRequest req(url); req.setRawHeader("User-Agent", agentStr.toLatin1()); if (!m_networkAccessManager) { m_networkAccessManager = new QNetworkAccessManager; m_networkAccessManager->setConfiguration(QNetworkConfiguration()); connect(m_networkAccessManager, SIGNAL(finished(QNetworkReply*)), SLOT(fetchingFinished(QNetworkReply*))); } m_requestCount++; m_networkAccessManager->get(req); }
// ---------------------------------------------------------------------------- // getNetworkConfiguration (static) // ---------------------------------------------------------------------------- QNetworkConfiguration NetworkTools::getNetworkConfiguration(const QNetworkConfiguration::BearerType &in_bearer_type) { QNetworkConfigurationManager nwc_manager; if (in_bearer_type == QNetworkConfiguration::BearerUnknown) return nwc_manager.defaultConfiguration(); QList<QNetworkConfiguration> nwc_list = nwc_manager.allConfigurations(QNetworkConfiguration::Discovered); if (nwc_list.isEmpty()) return QNetworkConfiguration(); // find interface ... QNetworkConfiguration temp, nwc; foreach (temp, nwc_list) { if (temp.bearerType() == in_bearer_type) { nwc = temp; break; } } return nwc; }
/*! Returns the network configuration of the proxy query. \sa setNetworkConfiguration() */ QNetworkConfiguration QNetworkProxyQuery::networkConfiguration() const { return d ? d->config : QNetworkConfiguration(); }