| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccessmanager.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 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 | #include "qnetworkaccessmanager.h" | - | ||||||||||||||||||
| 41 | #include "qnetworkaccessmanager_p.h" | - | ||||||||||||||||||
| 42 | #include "qnetworkrequest.h" | - | ||||||||||||||||||
| 43 | #include "qnetworkreply.h" | - | ||||||||||||||||||
| 44 | #include "qnetworkreply_p.h" | - | ||||||||||||||||||
| 45 | #include "qnetworkcookie.h" | - | ||||||||||||||||||
| 46 | #include "qnetworkcookiejar.h" | - | ||||||||||||||||||
| 47 | #include "qabstractnetworkcache.h" | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | #include "QtNetwork/qnetworksession.h" | - | ||||||||||||||||||
| 50 | #include "QtNetwork/private/qsharednetworksession_p.h" | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | #include "qnetworkaccessftpbackend_p.h" | - | ||||||||||||||||||
| 53 | #include "qnetworkaccessfilebackend_p.h" | - | ||||||||||||||||||
| 54 | #include "qnetworkaccessdebugpipebackend_p.h" | - | ||||||||||||||||||
| 55 | #include "qnetworkaccesscachebackend_p.h" | - | ||||||||||||||||||
| 56 | #include "qnetworkreplydataimpl_p.h" | - | ||||||||||||||||||
| 57 | #include "qnetworkreplyfileimpl_p.h" | - | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | #include "QtCore/qbuffer.h" | - | ||||||||||||||||||
| 60 | #include "QtCore/qurl.h" | - | ||||||||||||||||||
| 61 | #include "QtCore/qvector.h" | - | ||||||||||||||||||
| 62 | #include "QtNetwork/private/qauthenticator_p.h" | - | ||||||||||||||||||
| 63 | #include "QtNetwork/qsslconfiguration.h" | - | ||||||||||||||||||
| 64 | #include "QtNetwork/qnetworkconfigmanager.h" | - | ||||||||||||||||||
| 65 | #include "QtNetwork/qhttpmultipart.h" | - | ||||||||||||||||||
| 66 | #include "qhttpmultipart_p.h" | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | #include "qnetworkreplyhttpimpl_p.h" | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | #include "qthread.h" | - | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 73 | - | |||||||||||||||||||
| 74 | Q_GLOBAL_STATIC(QNetworkAccessFileBackendFactory, fileBackend) executed 10 times by 10 tests: end of blockExecuted by:
executed 10 times by 10 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 91 times by 10 tests: return &holder.value;Executed by:
| 0-91 | ||||||||||||||||||
| 75 | #ifndef QT_NO_FTP | - | ||||||||||||||||||
| 76 | Q_GLOBAL_STATIC(QNetworkAccessFtpBackendFactory, ftpBackend) executed 10 times by 10 tests: end of blockExecuted by:
executed 10 times by 10 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 91 times by 10 tests: return &holder.value;Executed by:
| 0-91 | ||||||||||||||||||
| 77 | #endif // QT_NO_FTP | - | ||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | #ifdef QT_BUILD_INTERNAL | - | ||||||||||||||||||
| 80 | Q_GLOBAL_STATIC(QNetworkAccessDebugPipeBackendFactory, debugpipeBackend) executed 10 times by 10 tests: end of blockExecuted by:
executed 10 times by 10 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 91 times by 10 tests: return &holder.value;Executed by:
| 0-91 | ||||||||||||||||||
| 81 | #endif | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | #include <CoreServices/CoreServices.h> | - | ||||||||||||||||||
| 86 | #include <SystemConfiguration/SystemConfiguration.h> | - | ||||||||||||||||||
| 87 | #include <Security/SecKeychain.h> | - | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | bool getProxyAuth(const QString& proxyHostname, const QString &scheme, QString& username, QString& password) | - | ||||||||||||||||||
| 90 | { | - | ||||||||||||||||||
| 91 | OSStatus err; | - | ||||||||||||||||||
| 92 | SecKeychainItemRef itemRef; | - | ||||||||||||||||||
| 93 | bool retValue = false; | - | ||||||||||||||||||
| 94 | SecProtocolType protocolType = kSecProtocolTypeAny; | - | ||||||||||||||||||
| 95 | if (scheme.compare(QLatin1String("ftp"),Qt::CaseInsensitive)==0) { | - | ||||||||||||||||||
| 96 | protocolType = kSecProtocolTypeFTPProxy; | - | ||||||||||||||||||
| 97 | } else if (scheme.compare(QLatin1String("http"),Qt::CaseInsensitive)==0 | - | ||||||||||||||||||
| 98 | || scheme.compare(QLatin1String("preconnect-http"),Qt::CaseInsensitive)==0) { | - | ||||||||||||||||||
| 99 | protocolType = kSecProtocolTypeHTTPProxy; | - | ||||||||||||||||||
| 100 | } else if (scheme.compare(QLatin1String("https"),Qt::CaseInsensitive)==0 | - | ||||||||||||||||||
| 101 | || scheme.compare(QLatin1String("preconnect-https"),Qt::CaseInsensitive)==0) { | - | ||||||||||||||||||
| 102 | protocolType = kSecProtocolTypeHTTPSProxy; | - | ||||||||||||||||||
| 103 | } | - | ||||||||||||||||||
| 104 | QByteArray proxyHostnameUtf8(proxyHostname.toUtf8()); | - | ||||||||||||||||||
| 105 | err = SecKeychainFindInternetPassword(NULL, | - | ||||||||||||||||||
| 106 | proxyHostnameUtf8.length(), proxyHostnameUtf8.constData(), | - | ||||||||||||||||||
| 107 | 0,NULL, | - | ||||||||||||||||||
| 108 | 0, NULL, | - | ||||||||||||||||||
| 109 | 0, NULL, | - | ||||||||||||||||||
| 110 | 0, | - | ||||||||||||||||||
| 111 | protocolType, | - | ||||||||||||||||||
| 112 | kSecAuthenticationTypeAny, | - | ||||||||||||||||||
| 113 | 0, NULL, | - | ||||||||||||||||||
| 114 | &itemRef); | - | ||||||||||||||||||
| 115 | if (err == noErr) { | - | ||||||||||||||||||
| 116 | - | |||||||||||||||||||
| 117 | SecKeychainAttribute attr; | - | ||||||||||||||||||
| 118 | SecKeychainAttributeList attrList; | - | ||||||||||||||||||
| 119 | UInt32 length; | - | ||||||||||||||||||
| 120 | void *outData; | - | ||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 | attr.tag = kSecAccountItemAttr; | - | ||||||||||||||||||
| 123 | attr.length = 0; | - | ||||||||||||||||||
| 124 | attr.data = NULL; | - | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | attrList.count = 1; | - | ||||||||||||||||||
| 127 | attrList.attr = &attr; | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | if (SecKeychainItemCopyContent(itemRef, NULL, &attrList, &length, &outData) == noErr) { | - | ||||||||||||||||||
| 130 | username = QString::fromUtf8((const char*)attr.data, attr.length); | - | ||||||||||||||||||
| 131 | password = QString::fromUtf8((const char*)outData, length); | - | ||||||||||||||||||
| 132 | SecKeychainItemFreeContent(&attrList,outData); | - | ||||||||||||||||||
| 133 | retValue = true; | - | ||||||||||||||||||
| 134 | } | - | ||||||||||||||||||
| 135 | CFRelease(itemRef); | - | ||||||||||||||||||
| 136 | } | - | ||||||||||||||||||
| 137 | return retValue; | - | ||||||||||||||||||
| 138 | } | - | ||||||||||||||||||
| 139 | #endif | - | ||||||||||||||||||
| 140 | - | |||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | static void ensureInitialized() | - | ||||||||||||||||||
| 144 | { | - | ||||||||||||||||||
| 145 | #ifndef QT_NO_FTP | - | ||||||||||||||||||
| 146 | (void) ftpBackend(); | - | ||||||||||||||||||
| 147 | #endif | - | ||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | #ifdef QT_BUILD_INTERNAL | - | ||||||||||||||||||
| 150 | (void) debugpipeBackend(); | - | ||||||||||||||||||
| 151 | #endif | - | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | // leave this one last since it will query the special QAbstractFileEngines | - | ||||||||||||||||||
| 154 | (void) fileBackend(); | - | ||||||||||||||||||
| 155 | } executed 91 times by 10 tests: end of blockExecuted by:
| 91 | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | /*! | - | ||||||||||||||||||
| 158 | \class QNetworkAccessManager | - | ||||||||||||||||||
| 159 | \brief The QNetworkAccessManager class allows the application to | - | ||||||||||||||||||
| 160 | send network requests and receive replies | - | ||||||||||||||||||
| 161 | \since 4.4 | - | ||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | \ingroup network | - | ||||||||||||||||||
| 164 | \inmodule QtNetwork | - | ||||||||||||||||||
| 165 | \reentrant | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | The Network Access API is constructed around one QNetworkAccessManager | - | ||||||||||||||||||
| 168 | object, which holds the common configuration and settings for the requests | - | ||||||||||||||||||
| 169 | it sends. It contains the proxy and cache configuration, as well as the | - | ||||||||||||||||||
| 170 | signals related to such issues, and reply signals that can be used to | - | ||||||||||||||||||
| 171 | monitor the progress of a network operation. One QNetworkAccessManager | - | ||||||||||||||||||
| 172 | should be enough for the whole Qt application. | - | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | Once a QNetworkAccessManager object has been created, the application can | - | ||||||||||||||||||
| 175 | use it to send requests over the network. A group of standard functions | - | ||||||||||||||||||
| 176 | are supplied that take a request and optional data, and each return a | - | ||||||||||||||||||
| 177 | QNetworkReply object. The returned object is used to obtain any data | - | ||||||||||||||||||
| 178 | returned in response to the corresponding request. | - | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | A simple download off the network could be accomplished with: | - | ||||||||||||||||||
| 181 | \snippet code/src_network_access_qnetworkaccessmanager.cpp 0 | - | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | QNetworkAccessManager has an asynchronous API. | - | ||||||||||||||||||
| 184 | When the \tt replyFinished slot above is called, the parameter it | - | ||||||||||||||||||
| 185 | takes is the QNetworkReply object containing the downloaded data | - | ||||||||||||||||||
| 186 | as well as meta-data (headers, etc.). | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | \note After the request has finished, it is the responsibility of the user | - | ||||||||||||||||||
| 189 | to delete the QNetworkReply object at an appropriate time. Do not directly | - | ||||||||||||||||||
| 190 | delete it inside the slot connected to finished(). You can use the | - | ||||||||||||||||||
| 191 | deleteLater() function. | - | ||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | \note QNetworkAccessManager queues the requests it receives. The number | - | ||||||||||||||||||
| 194 | of requests executed in parallel is dependent on the protocol. | - | ||||||||||||||||||
| 195 | Currently, for the HTTP protocol on desktop platforms, 6 requests are | - | ||||||||||||||||||
| 196 | executed in parallel for one host/port combination. | - | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | A more involved example, assuming the manager is already existent, | - | ||||||||||||||||||
| 199 | can be: | - | ||||||||||||||||||
| 200 | \snippet code/src_network_access_qnetworkaccessmanager.cpp 1 | - | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | \section1 Network and Roaming Support | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | With the addition of the \l {Bearer Management} API to Qt 4.7 | - | ||||||||||||||||||
| 205 | QNetworkAccessManager gained the ability to manage network connections. | - | ||||||||||||||||||
| 206 | QNetworkAccessManager can start the network interface if the device is | - | ||||||||||||||||||
| 207 | offline and terminates the interface if the current process is the last | - | ||||||||||||||||||
| 208 | one to use the uplink. Note that some platforms utilize grace periods from | - | ||||||||||||||||||
| 209 | when the last application stops using a uplink until the system actually | - | ||||||||||||||||||
| 210 | terminates the connectivity link. Roaming is equally transparent. Any | - | ||||||||||||||||||
| 211 | queued/pending network requests are automatically transferred to the new | - | ||||||||||||||||||
| 212 | access point. | - | ||||||||||||||||||
| 213 | - | |||||||||||||||||||
| 214 | Clients wanting to utilize this feature should not require any changes. In fact | - | ||||||||||||||||||
| 215 | it is likely that existing platform specific connection code can simply be | - | ||||||||||||||||||
| 216 | removed from the application. | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | \note The network and roaming support in QNetworkAccessManager is conditional | - | ||||||||||||||||||
| 219 | upon the platform supporting connection management. The | - | ||||||||||||||||||
| 220 | \l QNetworkConfigurationManager::NetworkSessionRequired can be used to | - | ||||||||||||||||||
| 221 | detect whether QNetworkAccessManager utilizes this feature. | - | ||||||||||||||||||
| 222 | - | |||||||||||||||||||
| 223 | \sa QNetworkRequest, QNetworkReply, QNetworkProxy | - | ||||||||||||||||||
| 224 | */ | - | ||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | /*! | - | ||||||||||||||||||
| 227 | \enum QNetworkAccessManager::Operation | - | ||||||||||||||||||
| 228 | - | |||||||||||||||||||
| 229 | Indicates the operation this reply is processing. | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | \value HeadOperation retrieve headers operation (created | - | ||||||||||||||||||
| 232 | with head()) | - | ||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | \value GetOperation retrieve headers and download contents | - | ||||||||||||||||||
| 235 | (created with get()) | - | ||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | \value PutOperation upload contents operation (created | - | ||||||||||||||||||
| 238 | with put()) | - | ||||||||||||||||||
| 239 | - | |||||||||||||||||||
| 240 | \value PostOperation send the contents of an HTML form for | - | ||||||||||||||||||
| 241 | processing via HTTP POST (created with post()) | - | ||||||||||||||||||
| 242 | - | |||||||||||||||||||
| 243 | \value DeleteOperation delete contents operation (created with | - | ||||||||||||||||||
| 244 | deleteResource()) | - | ||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | \value CustomOperation custom operation (created with | - | ||||||||||||||||||
| 247 | sendCustomRequest()) \since 4.7 | - | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | \omitvalue UnknownOperation | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | \sa QNetworkReply::operation() | - | ||||||||||||||||||
| 252 | */ | - | ||||||||||||||||||
| 253 | - | |||||||||||||||||||
| 254 | /*! | - | ||||||||||||||||||
| 255 | \enum QNetworkAccessManager::NetworkAccessibility | - | ||||||||||||||||||
| 256 | - | |||||||||||||||||||
| 257 | Indicates whether the network is accessible via this network access manager. | - | ||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | \value UnknownAccessibility The network accessibility cannot be determined. | - | ||||||||||||||||||
| 260 | \value NotAccessible The network is not currently accessible, either because there | - | ||||||||||||||||||
| 261 | is currently no network coverage or network access has been | - | ||||||||||||||||||
| 262 | explicitly disabled by a call to setNetworkAccessible(). | - | ||||||||||||||||||
| 263 | \value Accessible The network is accessible. | - | ||||||||||||||||||
| 264 | - | |||||||||||||||||||
| 265 | \sa networkAccessible | - | ||||||||||||||||||
| 266 | */ | - | ||||||||||||||||||
| 267 | - | |||||||||||||||||||
| 268 | /*! | - | ||||||||||||||||||
| 269 | \property QNetworkAccessManager::networkAccessible | - | ||||||||||||||||||
| 270 | \brief whether the network is currently accessible via this network access manager. | - | ||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | \since 4.7 | - | ||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | If the network is \l {NotAccessible}{not accessible} the network access manager will not | - | ||||||||||||||||||
| 275 | process any new network requests, all such requests will fail with an error. Requests with | - | ||||||||||||||||||
| 276 | URLs with the file:// scheme will still be processed. | - | ||||||||||||||||||
| 277 | - | |||||||||||||||||||
| 278 | By default the value of this property reflects the physical state of the device. Applications | - | ||||||||||||||||||
| 279 | may override it to disable all network requests via this network access manager by calling | - | ||||||||||||||||||
| 280 | - | |||||||||||||||||||
| 281 | \snippet code/src_network_access_qnetworkaccessmanager.cpp 4 | - | ||||||||||||||||||
| 282 | - | |||||||||||||||||||
| 283 | Network requests can be re-enabled again, and this property will resume to | - | ||||||||||||||||||
| 284 | reflect the actual device state by calling | - | ||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | \snippet code/src_network_access_qnetworkaccessmanager.cpp 5 | - | ||||||||||||||||||
| 287 | - | |||||||||||||||||||
| 288 | \note Calling setNetworkAccessible() does not change the network state. | - | ||||||||||||||||||
| 289 | */ | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | /*! | - | ||||||||||||||||||
| 292 | \fn void QNetworkAccessManager::networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility accessible) | - | ||||||||||||||||||
| 293 | - | |||||||||||||||||||
| 294 | This signal is emitted when the value of the \l networkAccessible property changes. | - | ||||||||||||||||||
| 295 | \a accessible is the new network accessibility. | - | ||||||||||||||||||
| 296 | */ | - | ||||||||||||||||||
| 297 | - | |||||||||||||||||||
| 298 | /*! | - | ||||||||||||||||||
| 299 | \fn void QNetworkAccessManager::networkSessionConnected() | - | ||||||||||||||||||
| 300 | - | |||||||||||||||||||
| 301 | \since 4.7 | - | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | \internal | - | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | This signal is emitted when the status of the network session changes into a usable (Connected) | - | ||||||||||||||||||
| 306 | state. It is used to signal to QNetworkReplys to start or migrate their network operation once | - | ||||||||||||||||||
| 307 | the network session has been opened or finished roaming. | - | ||||||||||||||||||
| 308 | */ | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | /*! | - | ||||||||||||||||||
| 311 | \fn void QNetworkAccessManager::proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator) | - | ||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | This signal is emitted whenever a proxy requests authentication | - | ||||||||||||||||||
| 314 | and QNetworkAccessManager cannot find a valid, cached | - | ||||||||||||||||||
| 315 | credential. The slot connected to this signal should fill in the | - | ||||||||||||||||||
| 316 | credentials for the proxy \a proxy in the \a authenticator object. | - | ||||||||||||||||||
| 317 | - | |||||||||||||||||||
| 318 | QNetworkAccessManager will cache the credentials internally. The | - | ||||||||||||||||||
| 319 | next time the proxy requests authentication, QNetworkAccessManager | - | ||||||||||||||||||
| 320 | will automatically send the same credential without emitting the | - | ||||||||||||||||||
| 321 | proxyAuthenticationRequired signal again. | - | ||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | If the proxy rejects the credentials, QNetworkAccessManager will | - | ||||||||||||||||||
| 324 | emit the signal again. | - | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | \sa proxy(), setProxy(), authenticationRequired() | - | ||||||||||||||||||
| 327 | */ | - | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | /*! | - | ||||||||||||||||||
| 330 | \fn void QNetworkAccessManager::authenticationRequired(QNetworkReply *reply, QAuthenticator *authenticator) | - | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | This signal is emitted whenever a final server requests | - | ||||||||||||||||||
| 333 | authentication before it delivers the requested contents. The slot | - | ||||||||||||||||||
| 334 | connected to this signal should fill the credentials for the | - | ||||||||||||||||||
| 335 | contents (which can be determined by inspecting the \a reply | - | ||||||||||||||||||
| 336 | object) in the \a authenticator object. | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | QNetworkAccessManager will cache the credentials internally and | - | ||||||||||||||||||
| 339 | will send the same values if the server requires authentication | - | ||||||||||||||||||
| 340 | again, without emitting the authenticationRequired() signal. If it | - | ||||||||||||||||||
| 341 | rejects the credentials, this signal will be emitted again. | - | ||||||||||||||||||
| 342 | - | |||||||||||||||||||
| 343 | \note To have the request not send credentials you must not call | - | ||||||||||||||||||
| 344 | setUser() or setPassword() on the \a authenticator object. This | - | ||||||||||||||||||
| 345 | will result in the \l finished() signal being emitted with a | - | ||||||||||||||||||
| 346 | \l QNetworkReply with error \l {QNetworkReply::} {AuthenticationRequiredError}. | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | \note It is not possible to use a QueuedConnection to connect to | - | ||||||||||||||||||
| 349 | this signal, as the connection will fail if the authenticator has | - | ||||||||||||||||||
| 350 | not been filled in with new information when the signal returns. | - | ||||||||||||||||||
| 351 | - | |||||||||||||||||||
| 352 | \sa proxyAuthenticationRequired(), QAuthenticator::setUser(), QAuthenticator::setPassword() | - | ||||||||||||||||||
| 353 | */ | - | ||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | /*! | - | ||||||||||||||||||
| 356 | \fn void QNetworkAccessManager::finished(QNetworkReply *reply) | - | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | This signal is emitted whenever a pending network reply is | - | ||||||||||||||||||
| 359 | finished. The \a reply parameter will contain a pointer to the | - | ||||||||||||||||||
| 360 | reply that has just finished. This signal is emitted in tandem | - | ||||||||||||||||||
| 361 | with the QNetworkReply::finished() signal. | - | ||||||||||||||||||
| 362 | - | |||||||||||||||||||
| 363 | See QNetworkReply::finished() for information on the status that | - | ||||||||||||||||||
| 364 | the object will be in. | - | ||||||||||||||||||
| 365 | - | |||||||||||||||||||
| 366 | \note Do not delete the \a reply object in the slot connected to this | - | ||||||||||||||||||
| 367 | signal. Use deleteLater(). | - | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | \sa QNetworkReply::finished(), QNetworkReply::error() | - | ||||||||||||||||||
| 370 | */ | - | ||||||||||||||||||
| 371 | - | |||||||||||||||||||
| 372 | /*! | - | ||||||||||||||||||
| 373 | \fn void QNetworkAccessManager::encrypted(QNetworkReply *reply) | - | ||||||||||||||||||
| 374 | \since 5.1 | - | ||||||||||||||||||
| 375 | - | |||||||||||||||||||
| 376 | This signal is emitted when an SSL/TLS session has successfully | - | ||||||||||||||||||
| 377 | completed the initial handshake. At this point, no user data | - | ||||||||||||||||||
| 378 | has been transmitted. The signal can be used to perform | - | ||||||||||||||||||
| 379 | additional checks on the certificate chain, for example to | - | ||||||||||||||||||
| 380 | notify users when the certificate for a website has changed. The | - | ||||||||||||||||||
| 381 | \a reply parameter specifies which network reply is responsible. | - | ||||||||||||||||||
| 382 | If the reply does not match the expected criteria then it should | - | ||||||||||||||||||
| 383 | be aborted by calling QNetworkReply::abort() by a slot connected | - | ||||||||||||||||||
| 384 | to this signal. The SSL configuration in use can be inspected | - | ||||||||||||||||||
| 385 | using the QNetworkReply::sslConfiguration() method. | - | ||||||||||||||||||
| 386 | - | |||||||||||||||||||
| 387 | Internally, QNetworkAccessManager may open multiple connections | - | ||||||||||||||||||
| 388 | to a server, in order to allow it process requests in parallel. | - | ||||||||||||||||||
| 389 | These connections may be reused, which means that the encrypted() | - | ||||||||||||||||||
| 390 | signal would not be emitted. This means that you are only | - | ||||||||||||||||||
| 391 | guaranteed to receive this signal for the first connection to a | - | ||||||||||||||||||
| 392 | site in the lifespan of the QNetworkAccessManager. | - | ||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | \sa QSslSocket::encrypted() | - | ||||||||||||||||||
| 395 | \sa QNetworkReply::encrypted() | - | ||||||||||||||||||
| 396 | */ | - | ||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | /*! | - | ||||||||||||||||||
| 399 | \fn void QNetworkAccessManager::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors) | - | ||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | This signal is emitted if the SSL/TLS session encountered errors | - | ||||||||||||||||||
| 402 | during the set up, including certificate verification errors. The | - | ||||||||||||||||||
| 403 | \a errors parameter contains the list of errors and \a reply is | - | ||||||||||||||||||
| 404 | the QNetworkReply that is encountering these errors. | - | ||||||||||||||||||
| 405 | - | |||||||||||||||||||
| 406 | To indicate that the errors are not fatal and that the connection | - | ||||||||||||||||||
| 407 | should proceed, the QNetworkReply::ignoreSslErrors() function should be called | - | ||||||||||||||||||
| 408 | from the slot connected to this signal. If it is not called, the | - | ||||||||||||||||||
| 409 | SSL session will be torn down before any data is exchanged | - | ||||||||||||||||||
| 410 | (including the URL). | - | ||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | This signal can be used to display an error message to the user | - | ||||||||||||||||||
| 413 | indicating that security may be compromised and display the | - | ||||||||||||||||||
| 414 | SSL settings (see sslConfiguration() to obtain it). If the user | - | ||||||||||||||||||
| 415 | decides to proceed after analyzing the remote certificate, the | - | ||||||||||||||||||
| 416 | slot should call ignoreSslErrors(). | - | ||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | \sa QSslSocket::sslErrors(), QNetworkReply::sslErrors(), | - | ||||||||||||||||||
| 419 | QNetworkReply::sslConfiguration(), QNetworkReply::ignoreSslErrors() | - | ||||||||||||||||||
| 420 | */ | - | ||||||||||||||||||
| 421 | - | |||||||||||||||||||
| 422 | /*! | - | ||||||||||||||||||
| 423 | \fn void QNetworkAccessManager::preSharedKeyAuthenticationRequired(QNetworkReply *reply, QSslPreSharedKeyAuthenticator *authenticator) | - | ||||||||||||||||||
| 424 | \since 5.5 | - | ||||||||||||||||||
| 425 | - | |||||||||||||||||||
| 426 | This signal is emitted if the SSL/TLS handshake negotiates a PSK | - | ||||||||||||||||||
| 427 | ciphersuite, and therefore a PSK authentication is then required. | - | ||||||||||||||||||
| 428 | The \a reply object is the QNetworkReply that is negotiating | - | ||||||||||||||||||
| 429 | such ciphersuites. | - | ||||||||||||||||||
| 430 | - | |||||||||||||||||||
| 431 | When using PSK, the client must send to the server a valid identity and a | - | ||||||||||||||||||
| 432 | valid pre shared key, in order for the SSL handshake to continue. | - | ||||||||||||||||||
| 433 | Applications can provide this information in a slot connected to this | - | ||||||||||||||||||
| 434 | signal, by filling in the passed \a authenticator object according to their | - | ||||||||||||||||||
| 435 | needs. | - | ||||||||||||||||||
| 436 | - | |||||||||||||||||||
| 437 | \note Ignoring this signal, or failing to provide the required credentials, | - | ||||||||||||||||||
| 438 | will cause the handshake to fail, and therefore the connection to be aborted. | - | ||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | \note The \a authenticator object is owned by the reply and must not be | - | ||||||||||||||||||
| 441 | deleted by the application. | - | ||||||||||||||||||
| 442 | - | |||||||||||||||||||
| 443 | \sa QSslPreSharedKeyAuthenticator | - | ||||||||||||||||||
| 444 | */ | - | ||||||||||||||||||
| 445 | - | |||||||||||||||||||
| 446 | /*! | - | ||||||||||||||||||
| 447 | Constructs a QNetworkAccessManager object that is the center of | - | ||||||||||||||||||
| 448 | the Network Access API and sets \a parent as the parent object. | - | ||||||||||||||||||
| 449 | */ | - | ||||||||||||||||||
| 450 | QNetworkAccessManager::QNetworkAccessManager(QObject *parent) | - | ||||||||||||||||||
| 451 | : QObject(*new QNetworkAccessManagerPrivate, parent) | - | ||||||||||||||||||
| 452 | { | - | ||||||||||||||||||
| 453 | ensureInitialized(); | - | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | qRegisterMetaType<QNetworkReply::NetworkError>(); | - | ||||||||||||||||||
| 456 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 457 | qRegisterMetaType<QNetworkProxy>(); | - | ||||||||||||||||||
| 458 | #endif | - | ||||||||||||||||||
| 459 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 460 | qRegisterMetaType<QList<QSslError> >(); | - | ||||||||||||||||||
| 461 | qRegisterMetaType<QSslConfiguration>(); | - | ||||||||||||||||||
| 462 | qRegisterMetaType<QSslPreSharedKeyAuthenticator *>(); | - | ||||||||||||||||||
| 463 | #endif | - | ||||||||||||||||||
| 464 | qRegisterMetaType<QList<QPair<QByteArray,QByteArray> > >(); | - | ||||||||||||||||||
| 465 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||
| 466 | qRegisterMetaType<QHttpNetworkRequest>(); | - | ||||||||||||||||||
| 467 | #endif | - | ||||||||||||||||||
| 468 | qRegisterMetaType<QNetworkReply::NetworkError>(); | - | ||||||||||||||||||
| 469 | qRegisterMetaType<QSharedPointer<char> >(); | - | ||||||||||||||||||
| 470 | - | |||||||||||||||||||
| 471 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 472 | Q_D(QNetworkAccessManager); | - | ||||||||||||||||||
| 473 | // if a session is required, we track online state through | - | ||||||||||||||||||
| 474 | // the QNetworkSession's signals if a request is already made. | - | ||||||||||||||||||
| 475 | // we need to track current accessibility state by default | - | ||||||||||||||||||
| 476 | // | - | ||||||||||||||||||
| 477 | connect(&d->networkConfigurationManager, SIGNAL(onlineStateChanged(bool)), | - | ||||||||||||||||||
| 478 | SLOT(_q_onlineStateChanged(bool))); | - | ||||||||||||||||||
| 479 | connect(&d->networkConfigurationManager, SIGNAL(configurationChanged(const QNetworkConfiguration &)), | - | ||||||||||||||||||
| 480 | SLOT(_q_configurationChanged(const QNetworkConfiguration &))); | - | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | #endif | - | ||||||||||||||||||
| 483 | } executed 91 times by 10 tests: end of blockExecuted by:
| 91 | ||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | /*! | - | ||||||||||||||||||
| 486 | Destroys the QNetworkAccessManager object and frees up any | - | ||||||||||||||||||
| 487 | resources. Note that QNetworkReply objects that are returned from | - | ||||||||||||||||||
| 488 | this class have this object set as their parents, which means that | - | ||||||||||||||||||
| 489 | they will be deleted along with it if you don't call | - | ||||||||||||||||||
| 490 | QObject::setParent() on them. | - | ||||||||||||||||||
| 491 | */ | - | ||||||||||||||||||
| 492 | QNetworkAccessManager::~QNetworkAccessManager() | - | ||||||||||||||||||
| 493 | { | - | ||||||||||||||||||
| 494 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 495 | delete d_func()->proxyFactory; | - | ||||||||||||||||||
| 496 | #endif | - | ||||||||||||||||||
| 497 | - | |||||||||||||||||||
| 498 | // Delete the QNetworkReply children first. | - | ||||||||||||||||||
| 499 | // Else a QAbstractNetworkCache might get deleted in ~QObject | - | ||||||||||||||||||
| 500 | // before a QNetworkReply that accesses the QAbstractNetworkCache | - | ||||||||||||||||||
| 501 | // object in its destructor. | - | ||||||||||||||||||
| 502 | qDeleteAll(findChildren<QNetworkReply *>()); | - | ||||||||||||||||||
| 503 | // The other children will be deleted in this ~QObject | - | ||||||||||||||||||
| 504 | // FIXME instead of this "hack" make the QNetworkReplyImpl | - | ||||||||||||||||||
| 505 | // properly watch the cache deletion, e.g. via a QWeakPointer. | - | ||||||||||||||||||
| 506 | } executed 92 times by 11 tests: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 509 | /*! | - | ||||||||||||||||||
| 510 | Returns the QNetworkProxy that the requests sent using this | - | ||||||||||||||||||
| 511 | QNetworkAccessManager object will use. The default value for the | - | ||||||||||||||||||
| 512 | proxy is QNetworkProxy::DefaultProxy. | - | ||||||||||||||||||
| 513 | - | |||||||||||||||||||
| 514 | \sa setProxy(), setProxyFactory(), proxyAuthenticationRequired() | - | ||||||||||||||||||
| 515 | */ | - | ||||||||||||||||||
| 516 | QNetworkProxy QNetworkAccessManager::proxy() const | - | ||||||||||||||||||
| 517 | { | - | ||||||||||||||||||
| 518 | return d_func()->proxy; never executed: return d_func()->proxy; | 0 | ||||||||||||||||||
| 519 | } | - | ||||||||||||||||||
| 520 | - | |||||||||||||||||||
| 521 | /*! | - | ||||||||||||||||||
| 522 | Sets the proxy to be used in future requests to be \a proxy. This | - | ||||||||||||||||||
| 523 | does not affect requests that have already been sent. The | - | ||||||||||||||||||
| 524 | proxyAuthenticationRequired() signal will be emitted if the proxy | - | ||||||||||||||||||
| 525 | requests authentication. | - | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | A proxy set with this function will be used for all requests | - | ||||||||||||||||||
| 528 | issued by QNetworkAccessManager. In some cases, it might be | - | ||||||||||||||||||
| 529 | necessary to select different proxies depending on the type of | - | ||||||||||||||||||
| 530 | request being sent or the destination host. If that's the case, | - | ||||||||||||||||||
| 531 | you should consider using setProxyFactory(). | - | ||||||||||||||||||
| 532 | - | |||||||||||||||||||
| 533 | \sa proxy(), proxyAuthenticationRequired() | - | ||||||||||||||||||
| 534 | */ | - | ||||||||||||||||||
| 535 | void QNetworkAccessManager::setProxy(const QNetworkProxy &proxy) | - | ||||||||||||||||||
| 536 | { | - | ||||||||||||||||||
| 537 | Q_D(QNetworkAccessManager); | - | ||||||||||||||||||
| 538 | delete d->proxyFactory; | - | ||||||||||||||||||
| 539 | d->proxy = proxy; | - | ||||||||||||||||||
| 540 | d->proxyFactory = 0; | - | ||||||||||||||||||
| 541 | } executed 788 times by 2 tests: end of blockExecuted by:
| 788 | ||||||||||||||||||
| 542 | - | |||||||||||||||||||
| 543 | /*! | - | ||||||||||||||||||
| 544 | \fn QNetworkProxyFactory *QNetworkAccessManager::proxyFactory() const | - | ||||||||||||||||||
| 545 | \since 4.5 | - | ||||||||||||||||||
| 546 | - | |||||||||||||||||||
| 547 | Returns the proxy factory that this QNetworkAccessManager object | - | ||||||||||||||||||
| 548 | is using to determine the proxies to be used for requests. | - | ||||||||||||||||||
| 549 | - | |||||||||||||||||||
| 550 | Note that the pointer returned by this function is managed by | - | ||||||||||||||||||
| 551 | QNetworkAccessManager and could be deleted at any time. | - | ||||||||||||||||||
| 552 | - | |||||||||||||||||||
| 553 | \sa setProxyFactory(), proxy() | - | ||||||||||||||||||
| 554 | */ | - | ||||||||||||||||||
| 555 | QNetworkProxyFactory *QNetworkAccessManager::proxyFactory() const | - | ||||||||||||||||||
| 556 | { | - | ||||||||||||||||||
| 557 | return d_func()->proxyFactory; never executed: return d_func()->proxyFactory; | 0 | ||||||||||||||||||
| 558 | } | - | ||||||||||||||||||
| 559 | - | |||||||||||||||||||
| 560 | /*! | - | ||||||||||||||||||
| 561 | \since 4.5 | - | ||||||||||||||||||
| 562 | - | |||||||||||||||||||
| 563 | Sets the proxy factory for this class to be \a factory. A proxy | - | ||||||||||||||||||
| 564 | factory is used to determine a more specific list of proxies to be | - | ||||||||||||||||||
| 565 | used for a given request, instead of trying to use the same proxy | - | ||||||||||||||||||
| 566 | value for all requests. | - | ||||||||||||||||||
| 567 | - | |||||||||||||||||||
| 568 | All queries sent by QNetworkAccessManager will have type | - | ||||||||||||||||||
| 569 | QNetworkProxyQuery::UrlRequest. | - | ||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | For example, a proxy factory could apply the following rules: | - | ||||||||||||||||||
| 572 | \list | - | ||||||||||||||||||
| 573 | \li if the target address is in the local network (for example, | - | ||||||||||||||||||
| 574 | if the hostname contains no dots or if it's an IP address in | - | ||||||||||||||||||
| 575 | the organization's range), return QNetworkProxy::NoProxy | - | ||||||||||||||||||
| 576 | \li if the request is FTP, return an FTP proxy | - | ||||||||||||||||||
| 577 | \li if the request is HTTP or HTTPS, then return an HTTP proxy | - | ||||||||||||||||||
| 578 | \li otherwise, return a SOCKSv5 proxy server | - | ||||||||||||||||||
| 579 | \endlist | - | ||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | The lifetime of the object \a factory will be managed by | - | ||||||||||||||||||
| 582 | QNetworkAccessManager. It will delete the object when necessary. | - | ||||||||||||||||||
| 583 | - | |||||||||||||||||||
| 584 | \note If a specific proxy is set with setProxy(), the factory will not | - | ||||||||||||||||||
| 585 | be used. | - | ||||||||||||||||||
| 586 | - | |||||||||||||||||||
| 587 | \sa proxyFactory(), setProxy(), QNetworkProxyQuery | - | ||||||||||||||||||
| 588 | */ | - | ||||||||||||||||||
| 589 | void QNetworkAccessManager::setProxyFactory(QNetworkProxyFactory *factory) | - | ||||||||||||||||||
| 590 | { | - | ||||||||||||||||||
| 591 | Q_D(QNetworkAccessManager); | - | ||||||||||||||||||
| 592 | delete d->proxyFactory; | - | ||||||||||||||||||
| 593 | d->proxyFactory = factory; | - | ||||||||||||||||||
| 594 | d->proxy = QNetworkProxy(); | - | ||||||||||||||||||
| 595 | } executed 20 times by 1 test: end of blockExecuted by:
| 20 | ||||||||||||||||||
| 596 | #endif | - | ||||||||||||||||||
| 597 | - | |||||||||||||||||||
| 598 | /*! | - | ||||||||||||||||||
| 599 | \since 4.5 | - | ||||||||||||||||||
| 600 | - | |||||||||||||||||||
| 601 | Returns the cache that is used to store data obtained from the network. | - | ||||||||||||||||||
| 602 | - | |||||||||||||||||||
| 603 | \sa setCache() | - | ||||||||||||||||||
| 604 | */ | - | ||||||||||||||||||
| 605 | QAbstractNetworkCache *QNetworkAccessManager::cache() const | - | ||||||||||||||||||
| 606 | { | - | ||||||||||||||||||
| 607 | Q_D(const QNetworkAccessManager); | - | ||||||||||||||||||
| 608 | return d->networkCache; never executed: return d->networkCache; | 0 | ||||||||||||||||||
| 609 | } | - | ||||||||||||||||||
| 610 | - | |||||||||||||||||||
| 611 | /*! | - | ||||||||||||||||||
| 612 | \since 4.5 | - | ||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | Sets the manager's network cache to be the \a cache specified. The cache | - | ||||||||||||||||||
| 615 | is used for all requests dispatched by the manager. | - | ||||||||||||||||||
| 616 | - | |||||||||||||||||||
| 617 | Use this function to set the network cache object to a class that implements | - | ||||||||||||||||||
| 618 | additional features, like saving the cookies to permanent storage. | - | ||||||||||||||||||
| 619 | - | |||||||||||||||||||
| 620 | \note QNetworkAccessManager takes ownership of the \a cache object. | - | ||||||||||||||||||
| 621 | - | |||||||||||||||||||
| 622 | QNetworkAccessManager by default does not have a set cache. | - | ||||||||||||||||||
| 623 | Qt provides a simple disk cache, QNetworkDiskCache, which can be used. | - | ||||||||||||||||||
| 624 | - | |||||||||||||||||||
| 625 | \sa cache(), QNetworkRequest::CacheLoadControl | - | ||||||||||||||||||
| 626 | */ | - | ||||||||||||||||||
| 627 | void QNetworkAccessManager::setCache(QAbstractNetworkCache *cache) | - | ||||||||||||||||||
| 628 | { | - | ||||||||||||||||||
| 629 | Q_D(QNetworkAccessManager); | - | ||||||||||||||||||
| 630 | if (d->networkCache != cache) {
| 94-614 | ||||||||||||||||||
| 631 | delete d->networkCache; | - | ||||||||||||||||||
| 632 | d->networkCache = cache; | - | ||||||||||||||||||
| 633 | if (d->networkCache)
| 25-69 | ||||||||||||||||||
| 634 | d->networkCache->setParent(this); executed 69 times by 3 tests: d->networkCache->setParent(this);Executed by:
| 69 | ||||||||||||||||||
| 635 | } executed 94 times by 3 tests: end of blockExecuted by:
| 94 | ||||||||||||||||||
| 636 | } executed 708 times by 3 tests: end of blockExecuted by:
| 708 | ||||||||||||||||||
| 637 | - | |||||||||||||||||||
| 638 | /*! | - | ||||||||||||||||||
| 639 | Returns the QNetworkCookieJar that is used to store cookies | - | ||||||||||||||||||
| 640 | obtained from the network as well as cookies that are about to be | - | ||||||||||||||||||
| 641 | sent. | - | ||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | \sa setCookieJar() | - | ||||||||||||||||||
| 644 | */ | - | ||||||||||||||||||
| 645 | QNetworkCookieJar *QNetworkAccessManager::cookieJar() const | - | ||||||||||||||||||
| 646 | { | - | ||||||||||||||||||
| 647 | Q_D(const QNetworkAccessManager); | - | ||||||||||||||||||
| 648 | if (!d->cookieJar)
| 0-13 | ||||||||||||||||||
| 649 | d->createCookieJar(); never executed: d->createCookieJar(); | 0 | ||||||||||||||||||
| 650 | return d->cookieJar; executed 13 times by 1 test: return d->cookieJar;Executed by:
| 13 | ||||||||||||||||||
| 651 | } | - | ||||||||||||||||||
| 652 | - | |||||||||||||||||||
| 653 | /*! | - | ||||||||||||||||||
| 654 | Sets the manager's cookie jar to be the \a cookieJar specified. | - | ||||||||||||||||||
| 655 | The cookie jar is used by all requests dispatched by the manager. | - | ||||||||||||||||||
| 656 | - | |||||||||||||||||||
| 657 | Use this function to set the cookie jar object to a class that | - | ||||||||||||||||||
| 658 | implements additional features, like saving the cookies to permanent | - | ||||||||||||||||||
| 659 | storage. | - | ||||||||||||||||||
| 660 | - | |||||||||||||||||||
| 661 | \note QNetworkAccessManager takes ownership of the \a cookieJar object. | - | ||||||||||||||||||
| 662 | - | |||||||||||||||||||
| 663 | If \a cookieJar is in the same thread as this QNetworkAccessManager, | - | ||||||||||||||||||
| 664 | it will set the parent of the \a cookieJar | - | ||||||||||||||||||
| 665 | so that the cookie jar is deleted when this | - | ||||||||||||||||||
| 666 | object is deleted as well. If you want to share cookie jars | - | ||||||||||||||||||
| 667 | between different QNetworkAccessManager objects, you may want to | - | ||||||||||||||||||
| 668 | set the cookie jar's parent to 0 after calling this function. | - | ||||||||||||||||||
| 669 | - | |||||||||||||||||||
| 670 | QNetworkAccessManager by default does not implement any cookie | - | ||||||||||||||||||
| 671 | policy of its own: it accepts all cookies sent by the server, as | - | ||||||||||||||||||
| 672 | long as they are well formed and meet the minimum security | - | ||||||||||||||||||
| 673 | requirements (cookie domain matches the request's and cookie path | - | ||||||||||||||||||
| 674 | matches the request's). In order to implement your own security | - | ||||||||||||||||||
| 675 | policy, override the QNetworkCookieJar::cookiesForUrl() and | - | ||||||||||||||||||
| 676 | QNetworkCookieJar::setCookiesFromUrl() virtual functions. Those | - | ||||||||||||||||||
| 677 | functions are called by QNetworkAccessManager when it detects a | - | ||||||||||||||||||
| 678 | new cookie. | - | ||||||||||||||||||
| 679 | - | |||||||||||||||||||
| 680 | \sa cookieJar(), QNetworkCookieJar::cookiesForUrl(), QNetworkCookieJar::setCookiesFromUrl() | - | ||||||||||||||||||
| 681 | */ | - | ||||||||||||||||||
| 682 | void QNetworkAccessManager::setCookieJar(QNetworkCookieJar *cookieJar) | - | ||||||||||||||||||
| 683 | { | - | ||||||||||||||||||
| 684 | Q_D(QNetworkAccessManager); | - | ||||||||||||||||||
| 685 | d->cookieJarCreated = true; | - | ||||||||||||||||||
| 686 | if (d->cookieJar != cookieJar) {
| 0 | ||||||||||||||||||
| 687 | if (d->cookieJar && d->cookieJar->parent() == this)
| 0 | ||||||||||||||||||
| 688 | delete d->cookieJar; never executed: delete d->cookieJar; | 0 | ||||||||||||||||||
| 689 | d->cookieJar = cookieJar; | - | ||||||||||||||||||
| 690 | if (thread() == cookieJar->thread())
| 0 | ||||||||||||||||||
| 691 | d->cookieJar->setParent(this); never executed: d->cookieJar->setParent(this); | 0 | ||||||||||||||||||
| 692 | } never executed: end of block | 0 | ||||||||||||||||||
| 693 | } never executed: end of block | 0 | ||||||||||||||||||
| 694 | - | |||||||||||||||||||
| 695 | /*! | - | ||||||||||||||||||
| 696 | Posts a request to obtain the network headers for \a request | - | ||||||||||||||||||
| 697 | and returns a new QNetworkReply object which will contain such headers. | - | ||||||||||||||||||
| 698 | - | |||||||||||||||||||
| 699 | The function is named after the HTTP request associated (HEAD). | - | ||||||||||||||||||
| 700 | */ | - | ||||||||||||||||||
| 701 | QNetworkReply *QNetworkAccessManager::head(const QNetworkRequest &request) | - | ||||||||||||||||||
| 702 | { | - | ||||||||||||||||||
| 703 | return d_func()->postProcess(createRequest(QNetworkAccessManager::HeadOperation, request)); executed 27 times by 1 test: return d_func()->postProcess(createRequest(QNetworkAccessManager::HeadOperation, request));Executed by:
| 27 | ||||||||||||||||||
| 704 | } | - | ||||||||||||||||||
| 705 | - | |||||||||||||||||||
| 706 | /*! | - | ||||||||||||||||||
| 707 | Posts a request to obtain the contents of the target \a request | - | ||||||||||||||||||
| 708 | and returns a new QNetworkReply object opened for reading which emits the | - | ||||||||||||||||||
| 709 | \l{QIODevice::readyRead()}{readyRead()} signal whenever new data | - | ||||||||||||||||||
| 710 | arrives. | - | ||||||||||||||||||
| 711 | - | |||||||||||||||||||
| 712 | The contents as well as associated headers will be downloaded. | - | ||||||||||||||||||
| 713 | - | |||||||||||||||||||
| 714 | \sa post(), put(), deleteResource(), sendCustomRequest() | - | ||||||||||||||||||
| 715 | */ | - | ||||||||||||||||||
| 716 | QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request) | - | ||||||||||||||||||
| 717 | { | - | ||||||||||||||||||
| 718 | return d_func()->postProcess(createRequest(QNetworkAccessManager::GetOperation, request)); executed 776 times by 9 tests: return d_func()->postProcess(createRequest(QNetworkAccessManager::GetOperation, request));Executed by:
| 776 | ||||||||||||||||||
| 719 | } | - | ||||||||||||||||||
| 720 | - | |||||||||||||||||||
| 721 | /*! | - | ||||||||||||||||||
| 722 | Sends an HTTP POST request to the destination specified by \a request | - | ||||||||||||||||||
| 723 | and returns a new QNetworkReply object opened for reading that will | - | ||||||||||||||||||
| 724 | contain the reply sent by the server. The contents of the \a data | - | ||||||||||||||||||
| 725 | device will be uploaded to the server. | - | ||||||||||||||||||
| 726 | - | |||||||||||||||||||
| 727 | \a data must be open for reading and must remain valid until the | - | ||||||||||||||||||
| 728 | finished() signal is emitted for this reply. | - | ||||||||||||||||||
| 729 | - | |||||||||||||||||||
| 730 | \note Sending a POST request on protocols other than HTTP and | - | ||||||||||||||||||
| 731 | HTTPS is undefined and will probably fail. | - | ||||||||||||||||||
| 732 | - | |||||||||||||||||||
| 733 | \sa get(), put(), deleteResource(), sendCustomRequest() | - | ||||||||||||||||||
| 734 | */ | - | ||||||||||||||||||
| 735 | QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, QIODevice *data) | - | ||||||||||||||||||
| 736 | { | - | ||||||||||||||||||
| 737 | return d_func()->postProcess(createRequest(QNetworkAccessManager::PostOperation, request, data)); executed 157 times by 3 tests: return d_func()->postProcess(createRequest(QNetworkAccessManager::PostOperation, request, data));Executed by:
| 157 | ||||||||||||||||||
| 738 | } | - | ||||||||||||||||||
| 739 | - | |||||||||||||||||||
| 740 | /*! | - | ||||||||||||||||||
| 741 | \overload | - | ||||||||||||||||||
| 742 | - | |||||||||||||||||||
| 743 | Sends the contents of the \a data byte array to the destination | - | ||||||||||||||||||
| 744 | specified by \a request. | - | ||||||||||||||||||
| 745 | */ | - | ||||||||||||||||||
| 746 | QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, const QByteArray &data) | - | ||||||||||||||||||
| 747 | { | - | ||||||||||||||||||
| 748 | QBuffer *buffer = new QBuffer; | - | ||||||||||||||||||
| 749 | buffer->setData(data); | - | ||||||||||||||||||
| 750 | buffer->open(QIODevice::ReadOnly); | - | ||||||||||||||||||
| 751 | - | |||||||||||||||||||
| 752 | QNetworkReply *reply = post(request, buffer); | - | ||||||||||||||||||
| 753 | buffer->setParent(reply); | - | ||||||||||||||||||
| 754 | return reply; executed 54 times by 3 tests: return reply;Executed by:
| 54 | ||||||||||||||||||
| 755 | } | - | ||||||||||||||||||
| 756 | - | |||||||||||||||||||
| 757 | /*! | - | ||||||||||||||||||
| 758 | \since 4.8 | - | ||||||||||||||||||
| 759 | - | |||||||||||||||||||
| 760 | \overload | - | ||||||||||||||||||
| 761 | - | |||||||||||||||||||
| 762 | Sends the contents of the \a multiPart message to the destination | - | ||||||||||||||||||
| 763 | specified by \a request. | - | ||||||||||||||||||
| 764 | - | |||||||||||||||||||
| 765 | This can be used for sending MIME multipart messages over HTTP. | - | ||||||||||||||||||
| 766 | - | |||||||||||||||||||
| 767 | \sa QHttpMultiPart, QHttpPart, put() | - | ||||||||||||||||||
| 768 | */ | - | ||||||||||||||||||
| 769 | QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, QHttpMultiPart *multiPart) | - | ||||||||||||||||||
| 770 | { | - | ||||||||||||||||||
| 771 | QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart); | - | ||||||||||||||||||
| 772 | QIODevice *device = multiPart->d_func()->device; | - | ||||||||||||||||||
| 773 | QNetworkReply *reply = post(newRequest, device); | - | ||||||||||||||||||
| 774 | return reply; executed 24 times by 2 tests: return reply;Executed by:
| 24 | ||||||||||||||||||
| 775 | } | - | ||||||||||||||||||
| 776 | - | |||||||||||||||||||
| 777 | /*! | - | ||||||||||||||||||
| 778 | \since 4.8 | - | ||||||||||||||||||
| 779 | - | |||||||||||||||||||
| 780 | \overload | - | ||||||||||||||||||
| 781 | - | |||||||||||||||||||
| 782 | Sends the contents of the \a multiPart message to the destination | - | ||||||||||||||||||
| 783 | specified by \a request. | - | ||||||||||||||||||
| 784 | - | |||||||||||||||||||
| 785 | This can be used for sending MIME multipart messages over HTTP. | - | ||||||||||||||||||
| 786 | - | |||||||||||||||||||
| 787 | \sa QHttpMultiPart, QHttpPart, post() | - | ||||||||||||||||||
| 788 | */ | - | ||||||||||||||||||
| 789 | QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, QHttpMultiPart *multiPart) | - | ||||||||||||||||||
| 790 | { | - | ||||||||||||||||||
| 791 | QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart); | - | ||||||||||||||||||
| 792 | QIODevice *device = multiPart->d_func()->device; | - | ||||||||||||||||||
| 793 | QNetworkReply *reply = put(newRequest, device); | - | ||||||||||||||||||
| 794 | return reply; never executed: return reply; | 0 | ||||||||||||||||||
| 795 | } | - | ||||||||||||||||||
| 796 | - | |||||||||||||||||||
| 797 | /*! | - | ||||||||||||||||||
| 798 | Uploads the contents of \a data to the destination \a request and | - | ||||||||||||||||||
| 799 | returnes a new QNetworkReply object that will be open for reply. | - | ||||||||||||||||||
| 800 | - | |||||||||||||||||||
| 801 | \a data must be opened for reading when this function is called | - | ||||||||||||||||||
| 802 | and must remain valid until the finished() signal is emitted for | - | ||||||||||||||||||
| 803 | this reply. | - | ||||||||||||||||||
| 804 | - | |||||||||||||||||||
| 805 | Whether anything will be available for reading from the returned | - | ||||||||||||||||||
| 806 | object is protocol dependent. For HTTP, the server may send a | - | ||||||||||||||||||
| 807 | small HTML page indicating the upload was successful (or not). | - | ||||||||||||||||||
| 808 | Other protocols will probably have content in their replies. | - | ||||||||||||||||||
| 809 | - | |||||||||||||||||||
| 810 | \note For HTTP, this request will send a PUT request, which most servers | - | ||||||||||||||||||
| 811 | do not allow. Form upload mechanisms, including that of uploading | - | ||||||||||||||||||
| 812 | files through HTML forms, use the POST mechanism. | - | ||||||||||||||||||
| 813 | - | |||||||||||||||||||
| 814 | \sa get(), post(), deleteResource(), sendCustomRequest() | - | ||||||||||||||||||
| 815 | */ | - | ||||||||||||||||||
| 816 | QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, QIODevice *data) | - | ||||||||||||||||||
| 817 | { | - | ||||||||||||||||||
| 818 | return d_func()->postProcess(createRequest(QNetworkAccessManager::PutOperation, request, data)); executed 95 times by 2 tests: return d_func()->postProcess(createRequest(QNetworkAccessManager::PutOperation, request, data));Executed by:
| 95 | ||||||||||||||||||
| 819 | } | - | ||||||||||||||||||
| 820 | - | |||||||||||||||||||
| 821 | /*! | - | ||||||||||||||||||
| 822 | \overload | - | ||||||||||||||||||
| 823 | - | |||||||||||||||||||
| 824 | Sends the contents of the \a data byte array to the destination | - | ||||||||||||||||||
| 825 | specified by \a request. | - | ||||||||||||||||||
| 826 | */ | - | ||||||||||||||||||
| 827 | QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, const QByteArray &data) | - | ||||||||||||||||||
| 828 | { | - | ||||||||||||||||||
| 829 | QBuffer *buffer = new QBuffer; | - | ||||||||||||||||||
| 830 | buffer->setData(data); | - | ||||||||||||||||||
| 831 | buffer->open(QIODevice::ReadOnly); | - | ||||||||||||||||||
| 832 | - | |||||||||||||||||||
| 833 | QNetworkReply *reply = put(request, buffer); | - | ||||||||||||||||||
| 834 | buffer->setParent(reply); | - | ||||||||||||||||||
| 835 | return reply; executed 55 times by 2 tests: return reply;Executed by:
| 55 | ||||||||||||||||||
| 836 | } | - | ||||||||||||||||||
| 837 | - | |||||||||||||||||||
| 838 | /*! | - | ||||||||||||||||||
| 839 | \since 4.6 | - | ||||||||||||||||||
| 840 | - | |||||||||||||||||||
| 841 | Sends a request to delete the resource identified by the URL of \a request. | - | ||||||||||||||||||
| 842 | - | |||||||||||||||||||
| 843 | \note This feature is currently available for HTTP only, performing an | - | ||||||||||||||||||
| 844 | HTTP DELETE request. | - | ||||||||||||||||||
| 845 | - | |||||||||||||||||||
| 846 | \sa get(), post(), put(), sendCustomRequest() | - | ||||||||||||||||||
| 847 | */ | - | ||||||||||||||||||
| 848 | QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &request) | - | ||||||||||||||||||
| 849 | { | - | ||||||||||||||||||
| 850 | return d_func()->postProcess(createRequest(QNetworkAccessManager::DeleteOperation, request)); executed 7 times by 1 test: return d_func()->postProcess(createRequest(QNetworkAccessManager::DeleteOperation, request));Executed by:
| 7 | ||||||||||||||||||
| 851 | } | - | ||||||||||||||||||
| 852 | - | |||||||||||||||||||
| 853 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | /*! | - | ||||||||||||||||||
| 856 | \since 4.7 | - | ||||||||||||||||||
| 857 | - | |||||||||||||||||||
| 858 | Sets the network configuration that will be used when creating the | - | ||||||||||||||||||
| 859 | \l {QNetworkSession}{network session} to \a config. | - | ||||||||||||||||||
| 860 | - | |||||||||||||||||||
| 861 | The network configuration is used to create and open a network session before any request that | - | ||||||||||||||||||
| 862 | requires network access is process. If no network configuration is explicitly set via this | - | ||||||||||||||||||
| 863 | function the network configuration returned by | - | ||||||||||||||||||
| 864 | QNetworkConfigurationManager::defaultConfiguration() will be used. | - | ||||||||||||||||||
| 865 | - | |||||||||||||||||||
| 866 | To restore the default network configuration set the network configuration to the value | - | ||||||||||||||||||
| 867 | returned from QNetworkConfigurationManager::defaultConfiguration(). | - | ||||||||||||||||||
| 868 | - | |||||||||||||||||||
| 869 | Setting a network configuration means that the QNetworkAccessManager instance will only | - | ||||||||||||||||||
| 870 | be using the specified one. In particular, if the default network configuration changes | - | ||||||||||||||||||
| 871 | (upon e.g. Wifi being available), this new configuration needs to be enabled | - | ||||||||||||||||||
| 872 | manually if desired. | - | ||||||||||||||||||
| 873 | - | |||||||||||||||||||
| 874 | \snippet code/src_network_access_qnetworkaccessmanager.cpp 2 | - | ||||||||||||||||||
| 875 | - | |||||||||||||||||||
| 876 | If an invalid network configuration is set, a network session will not be created. In this | - | ||||||||||||||||||
| 877 | case network requests will be processed regardless, but may fail. For example: | - | ||||||||||||||||||
| 878 | - | |||||||||||||||||||
| 879 | \snippet code/src_network_access_qnetworkaccessmanager.cpp 3 | - | ||||||||||||||||||
| 880 | - | |||||||||||||||||||
| 881 | \sa configuration(), QNetworkSession | - | ||||||||||||||||||
| 882 | */ | - | ||||||||||||||||||
| 883 | void QNetworkAccessManager::setConfiguration(const QNetworkConfiguration &config) | - | ||||||||||||||||||
| 884 | { | - | ||||||||||||||||||
| 885 | Q_D(QNetworkAccessManager); | - | ||||||||||||||||||
| 886 | d->networkConfiguration = config; | - | ||||||||||||||||||
| 887 | d->customNetworkConfiguration = true; | - | ||||||||||||||||||
| 888 | d->createSession(config); | - | ||||||||||||||||||
| 889 | } executed 26 times by 3 tests: end of blockExecuted by:
| 26 | ||||||||||||||||||
| 890 | - | |||||||||||||||||||
| 891 | /*! | - | ||||||||||||||||||
| 892 | \since 4.7 | - | ||||||||||||||||||
| 893 | - | |||||||||||||||||||
| 894 | Returns the network configuration that will be used to create the | - | ||||||||||||||||||
| 895 | \l {QNetworkSession}{network session} which will be used when processing network requests. | - | ||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | \sa setConfiguration(), activeConfiguration() | - | ||||||||||||||||||
| 898 | */ | - | ||||||||||||||||||
| 899 | QNetworkConfiguration QNetworkAccessManager::configuration() const | - | ||||||||||||||||||
| 900 | { | - | ||||||||||||||||||
| 901 | Q_D(const QNetworkAccessManager); | - | ||||||||||||||||||
| 902 | - | |||||||||||||||||||
| 903 | QSharedPointer<QNetworkSession> session(d->getNetworkSession()); | - | ||||||||||||||||||
| 904 | if (session) {
| 0 | ||||||||||||||||||
| 905 | return session->configuration(); never executed: return session->configuration(); | 0 | ||||||||||||||||||
| 906 | } else { | - | ||||||||||||||||||
| 907 | QNetworkConfigurationManager manager; | - | ||||||||||||||||||
| 908 | return manager.defaultConfiguration(); never executed: return manager.defaultConfiguration(); | 0 | ||||||||||||||||||
| 909 | } | - | ||||||||||||||||||
| 910 | } | - | ||||||||||||||||||
| 911 | - | |||||||||||||||||||
| 912 | /*! | - | ||||||||||||||||||
| 913 | \since 4.7 | - | ||||||||||||||||||
| 914 | - | |||||||||||||||||||
| 915 | Returns the current active network configuration. | - | ||||||||||||||||||
| 916 | - | |||||||||||||||||||
| 917 | If the network configuration returned by configuration() is of type | - | ||||||||||||||||||
| 918 | QNetworkConfiguration::ServiceNetwork this function will return the current active child | - | ||||||||||||||||||
| 919 | network configuration of that configuration. Otherwise returns the same network configuration | - | ||||||||||||||||||
| 920 | as configuration(). | - | ||||||||||||||||||
| 921 | - | |||||||||||||||||||
| 922 | Use this function to return the actual network configuration currently in use by the network | - | ||||||||||||||||||
| 923 | session. | - | ||||||||||||||||||
| 924 | - | |||||||||||||||||||
| 925 | \sa configuration() | - | ||||||||||||||||||
| 926 | */ | - | ||||||||||||||||||
| 927 | QNetworkConfiguration QNetworkAccessManager::activeConfiguration() const | - | ||||||||||||||||||
| 928 | { | - | ||||||||||||||||||
| 929 | Q_D(const QNetworkAccessManager); | - | ||||||||||||||||||
| 930 | - | |||||||||||||||||||
| 931 | QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession()); | - | ||||||||||||||||||
| 932 | QNetworkConfigurationManager manager; | - | ||||||||||||||||||
| 933 | if (networkSession) {
| 0 | ||||||||||||||||||
| 934 | return manager.configurationFromIdentifier( never executed: return manager.configurationFromIdentifier( networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); | 0 | ||||||||||||||||||
| 935 | networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); never executed: return manager.configurationFromIdentifier( networkSession->sessionProperty(QLatin1String("ActiveConfiguration")).toString()); | 0 | ||||||||||||||||||
| 936 | } else { | - | ||||||||||||||||||
| 937 | return manager.defaultConfiguration(); never executed: return manager.defaultConfiguration(); | 0 | ||||||||||||||||||
| 938 | } | - | ||||||||||||||||||
| 939 | } | - | ||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | /*! | - | ||||||||||||||||||
| 942 | \since 4.7 | - | ||||||||||||||||||
| 943 | - | |||||||||||||||||||
| 944 | Overrides the reported network accessibility. If \a accessible is NotAccessible the reported | - | ||||||||||||||||||
| 945 | network accessiblity will always be NotAccessible. Otherwise the reported network | - | ||||||||||||||||||
| 946 | accessibility will reflect the actual device state. | - | ||||||||||||||||||
| 947 | */ | - | ||||||||||||||||||
| 948 | void QNetworkAccessManager::setNetworkAccessible(QNetworkAccessManager::NetworkAccessibility accessible) | - | ||||||||||||||||||
| 949 | { | - | ||||||||||||||||||
| 950 | Q_D(QNetworkAccessManager); | - | ||||||||||||||||||
| 951 | - | |||||||||||||||||||
| 952 | d->defaultAccessControl = accessible == NotAccessible ? false : true;
| 1-2 | ||||||||||||||||||
| 953 | - | |||||||||||||||||||
| 954 | if (d->networkAccessible != accessible) {
| 0-3 | ||||||||||||||||||
| 955 | NetworkAccessibility previous = networkAccessible(); | - | ||||||||||||||||||
| 956 | d->networkAccessible = accessible; | - | ||||||||||||||||||
| 957 | NetworkAccessibility current = networkAccessible(); | - | ||||||||||||||||||
| 958 | if (previous != current)
| 0-3 | ||||||||||||||||||
| 959 | emit networkAccessibleChanged(current); executed 3 times by 1 test: networkAccessibleChanged(current);Executed by:
| 3 | ||||||||||||||||||
| 960 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 961 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 962 | - | |||||||||||||||||||
| 963 | /*! | - | ||||||||||||||||||
| 964 | \since 4.7 | - | ||||||||||||||||||
| 965 | - | |||||||||||||||||||
| 966 | Returns the current network accessibility. | - | ||||||||||||||||||
| 967 | */ | - | ||||||||||||||||||
| 968 | QNetworkAccessManager::NetworkAccessibility QNetworkAccessManager::networkAccessible() const | - | ||||||||||||||||||
| 969 | { | - | ||||||||||||||||||
| 970 | Q_D(const QNetworkAccessManager); | - | ||||||||||||||||||
| 971 | - | |||||||||||||||||||
| 972 | if (d->networkConfiguration.state().testFlag(QNetworkConfiguration::Undefined))
| 0-12 | ||||||||||||||||||
| 973 | return UnknownAccessibility; never executed: return UnknownAccessibility; | 0 | ||||||||||||||||||
| 974 | - | |||||||||||||||||||
| 975 | if (d->networkSessionRequired) {
| 0-12 | ||||||||||||||||||
| 976 | QSharedPointer<QNetworkSession> networkSession(d->getNetworkSession()); | - | ||||||||||||||||||
| 977 | if (networkSession) {
| 0 | ||||||||||||||||||
| 978 | // d->online holds online/offline state of this network session. | - | ||||||||||||||||||
| 979 | if (d->online)
| 0 | ||||||||||||||||||
| 980 | return d->networkAccessible; never executed: return d->networkAccessible; | 0 | ||||||||||||||||||
| 981 | else | - | ||||||||||||||||||
| 982 | return NotAccessible; never executed: return NotAccessible; | 0 | ||||||||||||||||||
| 983 | } else { | - | ||||||||||||||||||
| 984 | if (d->defaultAccessControl) {
| 0 | ||||||||||||||||||
| 985 | if (d->online)
| 0 | ||||||||||||||||||
| 986 | return d->networkAccessible; never executed: return d->networkAccessible; | 0 | ||||||||||||||||||
| 987 | else | - | ||||||||||||||||||
| 988 | return NotAccessible; never executed: return NotAccessible; | 0 | ||||||||||||||||||
| 989 | } | - | ||||||||||||||||||
| 990 | return (d->networkAccessible); never executed: return (d->networkAccessible); | 0 | ||||||||||||||||||
| 991 | } | - | ||||||||||||||||||
| 992 | } else { | - | ||||||||||||||||||
| 993 | if (d->online)
| 0-12 | ||||||||||||||||||
| 994 | return d->networkAccessible; executed 12 times by 1 test: return d->networkAccessible;Executed by:
| 12 | ||||||||||||||||||
| 995 | else | - | ||||||||||||||||||
| 996 | return NotAccessible; never executed: return NotAccessible; | 0 | ||||||||||||||||||
| 997 | } | - | ||||||||||||||||||
| 998 | } | - | ||||||||||||||||||
| 999 | - | |||||||||||||||||||
| 1000 | /*! | - | ||||||||||||||||||
| 1001 | \internal | - | ||||||||||||||||||
| 1002 | - | |||||||||||||||||||
| 1003 | Returns the network session currently in use. | - | ||||||||||||||||||
| 1004 | This can be changed at any time, ownership remains with the QNetworkAccessManager | - | ||||||||||||||||||
| 1005 | */ | - | ||||||||||||||||||
| 1006 | const QWeakPointer<const QNetworkSession> QNetworkAccessManagerPrivate::getNetworkSession(const QNetworkAccessManager *q) | - | ||||||||||||||||||
| 1007 | { | - | ||||||||||||||||||
| 1008 | return q->d_func()->networkSessionWeakRef; executed 30 times by 1 test: return q->d_func()->networkSessionWeakRef;Executed by:
| 30 | ||||||||||||||||||
| 1009 | } | - | ||||||||||||||||||
| 1010 | - | |||||||||||||||||||
| 1011 | QSharedPointer<QNetworkSession> QNetworkAccessManagerPrivate::getNetworkSession() const | - | ||||||||||||||||||
| 1012 | { | - | ||||||||||||||||||
| 1013 | if (networkSessionStrongRef)
| 28-4125 | ||||||||||||||||||
| 1014 | return networkSessionStrongRef; executed 4125 times by 8 tests: return networkSessionStrongRef;Executed by:
| 4125 | ||||||||||||||||||
| 1015 | return networkSessionWeakRef.toStrongRef(); executed 28 times by 2 tests: return networkSessionWeakRef.toStrongRef();Executed by:
| 28 | ||||||||||||||||||
| 1016 | } | - | ||||||||||||||||||
| 1017 | - | |||||||||||||||||||
| 1018 | #endif // QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1019 | - | |||||||||||||||||||
| 1020 | - | |||||||||||||||||||
| 1021 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1022 | /*! | - | ||||||||||||||||||
| 1023 | \since 5.2 | - | ||||||||||||||||||
| 1024 | - | |||||||||||||||||||
| 1025 | Initiates a connection to the host given by \a hostName at port \a port, using | - | ||||||||||||||||||
| 1026 | \a sslConfiguration. This function is useful to complete the TCP and SSL handshake | - | ||||||||||||||||||
| 1027 | to a host before the HTTPS request is made, resulting in a lower network latency. | - | ||||||||||||||||||
| 1028 | - | |||||||||||||||||||
| 1029 | \note Preconnecting a SPDY connection can be done by calling setAllowedNextProtocols() | - | ||||||||||||||||||
| 1030 | on \a sslConfiguration with QSslConfiguration::NextProtocolSpdy3_0 contained in | - | ||||||||||||||||||
| 1031 | the list of allowed protocols. When using SPDY, one single connection per host is | - | ||||||||||||||||||
| 1032 | enough, i.e. calling this method multiple times per host will not result in faster | - | ||||||||||||||||||
| 1033 | network transactions. | - | ||||||||||||||||||
| 1034 | - | |||||||||||||||||||
| 1035 | \note This function has no possibility to report errors. | - | ||||||||||||||||||
| 1036 | - | |||||||||||||||||||
| 1037 | \sa connectToHost(), get(), post(), put(), deleteResource() | - | ||||||||||||||||||
| 1038 | */ | - | ||||||||||||||||||
| 1039 | void QNetworkAccessManager::connectToHostEncrypted(const QString &hostName, quint16 port, | - | ||||||||||||||||||
| 1040 | const QSslConfiguration &sslConfiguration) | - | ||||||||||||||||||
| 1041 | { | - | ||||||||||||||||||
| 1042 | QUrl url; | - | ||||||||||||||||||
| 1043 | url.setHost(hostName); | - | ||||||||||||||||||
| 1044 | url.setPort(port); | - | ||||||||||||||||||
| 1045 | url.setScheme(QLatin1String("preconnect-https")); | - | ||||||||||||||||||
| 1046 | QNetworkRequest request(url); | - | ||||||||||||||||||
| 1047 | if (sslConfiguration != QSslConfiguration::defaultConfiguration())
| 0 | ||||||||||||||||||
| 1048 | request.setSslConfiguration(sslConfiguration); never executed: request.setSslConfiguration(sslConfiguration); | 0 | ||||||||||||||||||
| 1049 | - | |||||||||||||||||||
| 1050 | // There is no way to enable SPDY via a request, so we need to check | - | ||||||||||||||||||
| 1051 | // the ssl configuration whether SPDY is allowed here. | - | ||||||||||||||||||
| 1052 | if (sslConfiguration.allowedNextProtocols().contains(
| 0 | ||||||||||||||||||
| 1053 | QSslConfiguration::NextProtocolSpdy3_0))
| 0 | ||||||||||||||||||
| 1054 | request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); never executed: request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); | 0 | ||||||||||||||||||
| 1055 | - | |||||||||||||||||||
| 1056 | get(request); | - | ||||||||||||||||||
| 1057 | } never executed: end of block | 0 | ||||||||||||||||||
| 1058 | #endif | - | ||||||||||||||||||
| 1059 | - | |||||||||||||||||||
| 1060 | /*! | - | ||||||||||||||||||
| 1061 | \since 5.2 | - | ||||||||||||||||||
| 1062 | - | |||||||||||||||||||
| 1063 | Initiates a connection to the host given by \a hostName at port \a port. | - | ||||||||||||||||||
| 1064 | This function is useful to complete the TCP handshake | - | ||||||||||||||||||
| 1065 | to a host before the HTTP request is made, resulting in a lower network latency. | - | ||||||||||||||||||
| 1066 | - | |||||||||||||||||||
| 1067 | \note This function has no possibility to report errors. | - | ||||||||||||||||||
| 1068 | - | |||||||||||||||||||
| 1069 | \sa connectToHostEncrypted(), get(), post(), put(), deleteResource() | - | ||||||||||||||||||
| 1070 | */ | - | ||||||||||||||||||
| 1071 | void QNetworkAccessManager::connectToHost(const QString &hostName, quint16 port) | - | ||||||||||||||||||
| 1072 | { | - | ||||||||||||||||||
| 1073 | QUrl url; | - | ||||||||||||||||||
| 1074 | url.setHost(hostName); | - | ||||||||||||||||||
| 1075 | url.setPort(port); | - | ||||||||||||||||||
| 1076 | url.setScheme(QLatin1String("preconnect-http")); | - | ||||||||||||||||||
| 1077 | QNetworkRequest request(url); | - | ||||||||||||||||||
| 1078 | get(request); | - | ||||||||||||||||||
| 1079 | } never executed: end of block | 0 | ||||||||||||||||||
| 1080 | - | |||||||||||||||||||
| 1081 | /*! | - | ||||||||||||||||||
| 1082 | \since 4.7 | - | ||||||||||||||||||
| 1083 | - | |||||||||||||||||||
| 1084 | Sends a custom request to the server identified by the URL of \a request. | - | ||||||||||||||||||
| 1085 | - | |||||||||||||||||||
| 1086 | It is the user's responsibility to send a \a verb to the server that is valid | - | ||||||||||||||||||
| 1087 | according to the HTTP specification. | - | ||||||||||||||||||
| 1088 | - | |||||||||||||||||||
| 1089 | This method provides means to send verbs other than the common ones provided | - | ||||||||||||||||||
| 1090 | via get() or post() etc., for instance sending an HTTP OPTIONS command. | - | ||||||||||||||||||
| 1091 | - | |||||||||||||||||||
| 1092 | If \a data is not empty, the contents of the \a data | - | ||||||||||||||||||
| 1093 | device will be uploaded to the server; in that case, data must be open for | - | ||||||||||||||||||
| 1094 | reading and must remain valid until the finished() signal is emitted for this reply. | - | ||||||||||||||||||
| 1095 | - | |||||||||||||||||||
| 1096 | \note This feature is currently available for HTTP(S) only. | - | ||||||||||||||||||
| 1097 | - | |||||||||||||||||||
| 1098 | \sa get(), post(), put(), deleteResource() | - | ||||||||||||||||||
| 1099 | */ | - | ||||||||||||||||||
| 1100 | QNetworkReply *QNetworkAccessManager::sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data) | - | ||||||||||||||||||
| 1101 | { | - | ||||||||||||||||||
| 1102 | QNetworkRequest newRequest(request); | - | ||||||||||||||||||
| 1103 | newRequest.setAttribute(QNetworkRequest::CustomVerbAttribute, verb); | - | ||||||||||||||||||
| 1104 | return d_func()->postProcess(createRequest(QNetworkAccessManager::CustomOperation, newRequest, data)); executed 7 times by 1 test: return d_func()->postProcess(createRequest(QNetworkAccessManager::CustomOperation, newRequest, data));Executed by:
| 7 | ||||||||||||||||||
| 1105 | } | - | ||||||||||||||||||
| 1106 | - | |||||||||||||||||||
| 1107 | /*! | - | ||||||||||||||||||
| 1108 | Returns a new QNetworkReply object to handle the operation \a op | - | ||||||||||||||||||
| 1109 | and request \a req. The device \a outgoingData is always 0 for Get and | - | ||||||||||||||||||
| 1110 | Head requests, but is the value passed to post() and put() in | - | ||||||||||||||||||
| 1111 | those operations (the QByteArray variants will pass a QBuffer | - | ||||||||||||||||||
| 1112 | object). | - | ||||||||||||||||||
| 1113 | - | |||||||||||||||||||
| 1114 | The default implementation calls QNetworkCookieJar::cookiesForUrl() | - | ||||||||||||||||||
| 1115 | on the cookie jar set with setCookieJar() to obtain the cookies to | - | ||||||||||||||||||
| 1116 | be sent to the remote server. | - | ||||||||||||||||||
| 1117 | - | |||||||||||||||||||
| 1118 | The returned object must be in an open state. | - | ||||||||||||||||||
| 1119 | */ | - | ||||||||||||||||||
| 1120 | QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Operation op, | - | ||||||||||||||||||
| 1121 | const QNetworkRequest &req, | - | ||||||||||||||||||
| 1122 | QIODevice *outgoingData) | - | ||||||||||||||||||
| 1123 | { | - | ||||||||||||||||||
| 1124 | Q_D(QNetworkAccessManager); | - | ||||||||||||||||||
| 1125 | - | |||||||||||||||||||
| 1126 | bool isLocalFile = req.url().isLocalFile(); | - | ||||||||||||||||||
| 1127 | QString scheme = req.url().scheme(); | - | ||||||||||||||||||
| 1128 | - | |||||||||||||||||||
| 1129 | // fast path for GET on file:// URLs | - | ||||||||||||||||||
| 1130 | // The QNetworkAccessFileBackend will right now only be used for PUT | - | ||||||||||||||||||
| 1131 | if (op == QNetworkAccessManager::GetOperation
| 293-776 | ||||||||||||||||||
| 1132 | || op == QNetworkAccessManager::HeadOperation) {
| 27-266 | ||||||||||||||||||
| 1133 | if (isLocalFile
| 28-775 | ||||||||||||||||||
| 1134 | #ifdef Q_OS_ANDROID | - | ||||||||||||||||||
| 1135 | || scheme == QLatin1String("assets") | - | ||||||||||||||||||
| 1136 | #endif | - | ||||||||||||||||||
| 1137 | || scheme == QLatin1String("qrc")) {
| 2-773 | ||||||||||||||||||
| 1138 | return new QNetworkReplyFileImpl(this, req, op); executed 30 times by 2 tests: return new QNetworkReplyFileImpl(this, req, op);Executed by:
| 30 | ||||||||||||||||||
| 1139 | } | - | ||||||||||||||||||
| 1140 | - | |||||||||||||||||||
| 1141 | if (scheme == QLatin1String("data"))
| 30-743 | ||||||||||||||||||
| 1142 | return new QNetworkReplyDataImpl(this, req, op); executed 30 times by 1 test: return new QNetworkReplyDataImpl(this, req, op);Executed by:
| 30 | ||||||||||||||||||
| 1143 | - | |||||||||||||||||||
| 1144 | // A request with QNetworkRequest::AlwaysCache does not need any bearer management | - | ||||||||||||||||||
| 1145 | QNetworkRequest::CacheLoadControl mode = | - | ||||||||||||||||||
| 1146 | static_cast<QNetworkRequest::CacheLoadControl>( | - | ||||||||||||||||||
| 1147 | req.attribute(QNetworkRequest::CacheLoadControlAttribute, | - | ||||||||||||||||||
| 1148 | QNetworkRequest::PreferNetwork).toInt()); | - | ||||||||||||||||||
| 1149 | if (mode == QNetworkRequest::AlwaysCache) {
| 14-729 | ||||||||||||||||||
| 1150 | // FIXME Implement a QNetworkReplyCacheImpl instead, see QTBUG-15106 | - | ||||||||||||||||||
| 1151 | QNetworkReplyImpl *reply = new QNetworkReplyImpl(this); | - | ||||||||||||||||||
| 1152 | QNetworkReplyImplPrivate *priv = reply->d_func(); | - | ||||||||||||||||||
| 1153 | priv->manager = this; | - | ||||||||||||||||||
| 1154 | priv->backend = new QNetworkAccessCacheBackend(); | - | ||||||||||||||||||
| 1155 | priv->backend->manager = this->d_func(); | - | ||||||||||||||||||
| 1156 | priv->backend->setParent(reply); | - | ||||||||||||||||||
| 1157 | priv->backend->reply = priv; | - | ||||||||||||||||||
| 1158 | priv->setup(op, req, outgoingData); | - | ||||||||||||||||||
| 1159 | return reply; executed 14 times by 3 tests: return reply;Executed by:
| 14 | ||||||||||||||||||
| 1160 | } | - | ||||||||||||||||||
| 1161 | } executed 729 times by 7 tests: end of blockExecuted by:
| 729 | ||||||||||||||||||
| 1162 | - | |||||||||||||||||||
| 1163 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1164 | // Return a disabled network reply if network access is disabled. | - | ||||||||||||||||||
| 1165 | // Except if the scheme is empty or file://. | - | ||||||||||||||||||
| 1166 | if (d->networkAccessible == NotAccessible && !isLocalFile) {
| 0-995 | ||||||||||||||||||
| 1167 | return new QDisabledNetworkReply(this, req, op); never executed: return new QDisabledNetworkReply(this, req, op); | 0 | ||||||||||||||||||
| 1168 | } | - | ||||||||||||||||||
| 1169 | - | |||||||||||||||||||
| 1170 | if (!d->networkSessionStrongRef && (d->initializeSession || !d->networkConfiguration.identifier().isEmpty())) {
| 0-799 | ||||||||||||||||||
| 1171 | QNetworkConfigurationManager manager; | - | ||||||||||||||||||
| 1172 | if (!d->networkConfiguration.identifier().isEmpty()) {
| 0-196 | ||||||||||||||||||
| 1173 | if ((d->networkConfiguration.state() & QNetworkConfiguration::Defined) | - | ||||||||||||||||||
| 1174 | && d->networkConfiguration != manager.defaultConfiguration())
| 0-196 | ||||||||||||||||||
| 1175 | d->createSession(manager.defaultConfiguration()); never executed: d->createSession(manager.defaultConfiguration()); | 0 | ||||||||||||||||||
| 1176 | else | - | ||||||||||||||||||
| 1177 | d->createSession(d->networkConfiguration); executed 196 times by 7 tests: d->createSession(d->networkConfiguration);Executed by:
| 196 | ||||||||||||||||||
| 1178 | - | |||||||||||||||||||
| 1179 | } else { | - | ||||||||||||||||||
| 1180 | if (manager.capabilities() & QNetworkConfigurationManager::NetworkSessionRequired)
| 0 | ||||||||||||||||||
| 1181 | d->createSession(manager.defaultConfiguration()); never executed: d->createSession(manager.defaultConfiguration()); | 0 | ||||||||||||||||||
| 1182 | else | - | ||||||||||||||||||
| 1183 | d->initializeSession = false; never executed: d->initializeSession = false; | 0 | ||||||||||||||||||
| 1184 | } | - | ||||||||||||||||||
| 1185 | } | - | ||||||||||||||||||
| 1186 | #endif | - | ||||||||||||||||||
| 1187 | - | |||||||||||||||||||
| 1188 | QNetworkRequest request = req; | - | ||||||||||||||||||
| 1189 | if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() &&
| 3-992 | ||||||||||||||||||
| 1190 | outgoingData && !outgoingData->isSequential()) {
| 93-740 | ||||||||||||||||||
| 1191 | // request has no Content-Length | - | ||||||||||||||||||
| 1192 | // but the data that is outgoing is random-access | - | ||||||||||||||||||
| 1193 | request.setHeader(QNetworkRequest::ContentLengthHeader, outgoingData->size()); | - | ||||||||||||||||||
| 1194 | } executed 159 times by 2 tests: end of blockExecuted by:
| 159 | ||||||||||||||||||
| 1195 | - | |||||||||||||||||||
| 1196 | if (static_cast<QNetworkRequest::LoadControl>
| 0-995 | ||||||||||||||||||
| 1197 | (request.attribute(QNetworkRequest::CookieLoadControlAttribute,
| 0-995 | ||||||||||||||||||
| 1198 | QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic) {
| 0-995 | ||||||||||||||||||
| 1199 | if (d->cookieJar) {
| 345-650 | ||||||||||||||||||
| 1200 | QList<QNetworkCookie> cookies = d->cookieJar->cookiesForUrl(request.url()); | - | ||||||||||||||||||
| 1201 | if (!cookies.isEmpty())
| 8-642 | ||||||||||||||||||
| 1202 | request.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue(cookies)); executed 8 times by 1 test: request.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue(cookies));Executed by:
| 8 | ||||||||||||||||||
| 1203 | } executed 650 times by 1 test: end of blockExecuted by:
| 650 | ||||||||||||||||||
| 1204 | } executed 995 times by 8 tests: end of blockExecuted by:
| 995 | ||||||||||||||||||
| 1205 | - | |||||||||||||||||||
| 1206 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||
| 1207 | // Since Qt 5 we use the new QNetworkReplyHttpImpl | - | ||||||||||||||||||
| 1208 | if (scheme == QLatin1String("http") || scheme == QLatin1String("preconnect-http")
| 0-655 | ||||||||||||||||||
| 1209 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1210 | || scheme == QLatin1String("https") || scheme == QLatin1String("preconnect-https")
| 0-232 | ||||||||||||||||||
| 1211 | #endif | - | ||||||||||||||||||
| 1212 | ) { | - | ||||||||||||||||||
| 1213 | QNetworkReplyHttpImpl *reply = new QNetworkReplyHttpImpl(this, request, op, outgoingData); | - | ||||||||||||||||||
| 1214 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1215 | connect(this, SIGNAL(networkSessionConnected()), | - | ||||||||||||||||||
| 1216 | reply, SLOT(_q_networkSessionConnected())); | - | ||||||||||||||||||
| 1217 | #endif | - | ||||||||||||||||||
| 1218 | return reply; executed 887 times by 8 tests: return reply;Executed by:
| 887 | ||||||||||||||||||
| 1219 | } | - | ||||||||||||||||||
| 1220 | #endif // QT_NO_HTTP | - | ||||||||||||||||||
| 1221 | - | |||||||||||||||||||
| 1222 | // first step: create the reply | - | ||||||||||||||||||
| 1223 | QNetworkReplyImpl *reply = new QNetworkReplyImpl(this); | - | ||||||||||||||||||
| 1224 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1225 | if (!isLocalFile) {
| 39-69 | ||||||||||||||||||
| 1226 | connect(this, SIGNAL(networkSessionConnected()), | - | ||||||||||||||||||
| 1227 | reply, SLOT(_q_networkSessionConnected())); | - | ||||||||||||||||||
| 1228 | } executed 69 times by 1 test: end of blockExecuted by:
| 69 | ||||||||||||||||||
| 1229 | #endif | - | ||||||||||||||||||
| 1230 | QNetworkReplyImplPrivate *priv = reply->d_func(); | - | ||||||||||||||||||
| 1231 | priv->manager = this; | - | ||||||||||||||||||
| 1232 | - | |||||||||||||||||||
| 1233 | // second step: fetch cached credentials | - | ||||||||||||||||||
| 1234 | // This is not done for the time being, we should use signal emissions to request | - | ||||||||||||||||||
| 1235 | // the credentials from cache. | - | ||||||||||||||||||
| 1236 | - | |||||||||||||||||||
| 1237 | // third step: find a backend | - | ||||||||||||||||||
| 1238 | priv->backend = d->findBackend(op, request); | - | ||||||||||||||||||
| 1239 | - | |||||||||||||||||||
| 1240 | if (priv->backend) {
| 4-104 | ||||||||||||||||||
| 1241 | priv->backend->setParent(reply); | - | ||||||||||||||||||
| 1242 | priv->backend->reply = priv; | - | ||||||||||||||||||
| 1243 | } executed 104 times by 1 test: end of blockExecuted by:
| 104 | ||||||||||||||||||
| 1244 | - | |||||||||||||||||||
| 1245 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1246 | reply->setSslConfiguration(request.sslConfiguration()); | - | ||||||||||||||||||
| 1247 | #endif | - | ||||||||||||||||||
| 1248 | - | |||||||||||||||||||
| 1249 | // fourth step: setup the reply | - | ||||||||||||||||||
| 1250 | priv->setup(op, request, outgoingData); | - | ||||||||||||||||||
| 1251 | - | |||||||||||||||||||
| 1252 | return reply; executed 108 times by 1 test: return reply;Executed by:
| 108 | ||||||||||||||||||
| 1253 | } | - | ||||||||||||||||||
| 1254 | - | |||||||||||||||||||
| 1255 | /*! | - | ||||||||||||||||||
| 1256 | \since 5.2 | - | ||||||||||||||||||
| 1257 | - | |||||||||||||||||||
| 1258 | Lists all the URL schemes supported by the access manager. | - | ||||||||||||||||||
| 1259 | - | |||||||||||||||||||
| 1260 | \sa supportedSchemesImplementation() | - | ||||||||||||||||||
| 1261 | */ | - | ||||||||||||||||||
| 1262 | QStringList QNetworkAccessManager::supportedSchemes() const | - | ||||||||||||||||||
| 1263 | { | - | ||||||||||||||||||
| 1264 | QStringList schemes; | - | ||||||||||||||||||
| 1265 | QNetworkAccessManager *self = const_cast<QNetworkAccessManager *>(this); // We know we call a const slot | - | ||||||||||||||||||
| 1266 | QMetaObject::invokeMethod(self, "supportedSchemesImplementation", Qt::DirectConnection, | - | ||||||||||||||||||
| 1267 | Q_RETURN_ARG(QStringList, schemes)); | - | ||||||||||||||||||
| 1268 | schemes.removeDuplicates(); | - | ||||||||||||||||||
| 1269 | return schemes; never executed: return schemes; | 0 | ||||||||||||||||||
| 1270 | } | - | ||||||||||||||||||
| 1271 | - | |||||||||||||||||||
| 1272 | /*! | - | ||||||||||||||||||
| 1273 | \since 5.2 | - | ||||||||||||||||||
| 1274 | - | |||||||||||||||||||
| 1275 | Lists all the URL schemes supported by the access manager. | - | ||||||||||||||||||
| 1276 | - | |||||||||||||||||||
| 1277 | You should not call this function directly; use | - | ||||||||||||||||||
| 1278 | QNetworkAccessManager::supportedSchemes() instead. | - | ||||||||||||||||||
| 1279 | - | |||||||||||||||||||
| 1280 | Reimplement this slot to provide your own supported schemes | - | ||||||||||||||||||
| 1281 | in a QNetworkAccessManager subclass. It is for instance necessary | - | ||||||||||||||||||
| 1282 | when your subclass provides support for new protocols. | - | ||||||||||||||||||
| 1283 | - | |||||||||||||||||||
| 1284 | Because of binary compatibility constraints, the supportedSchemes() | - | ||||||||||||||||||
| 1285 | method (introduced in Qt 5.2) is not virtual. Instead, supportedSchemes() | - | ||||||||||||||||||
| 1286 | will dynamically detect and call this slot. | - | ||||||||||||||||||
| 1287 | - | |||||||||||||||||||
| 1288 | \sa supportedSchemes() | - | ||||||||||||||||||
| 1289 | */ | - | ||||||||||||||||||
| 1290 | QStringList QNetworkAccessManager::supportedSchemesImplementation() const | - | ||||||||||||||||||
| 1291 | { | - | ||||||||||||||||||
| 1292 | Q_D(const QNetworkAccessManager); | - | ||||||||||||||||||
| 1293 | - | |||||||||||||||||||
| 1294 | QStringList schemes = d->backendSupportedSchemes(); | - | ||||||||||||||||||
| 1295 | // Those ones don't exist in backends | - | ||||||||||||||||||
| 1296 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||
| 1297 | schemes << QStringLiteral("http"); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 1298 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1299 | if (QSslSocket::supportsSsl())
| 0 | ||||||||||||||||||
| 1300 | schemes << QStringLiteral("https"); never executed: schemes << ([]() -> QString { enum { Size = sizeof(u"" "https")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "https" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }());never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 1301 | #endif | - | ||||||||||||||||||
| 1302 | #endif | - | ||||||||||||||||||
| 1303 | schemes << QStringLiteral("data"); never executed: return qstring_literal_temp; | 0 | ||||||||||||||||||
| 1304 | return schemes; never executed: return schemes; | 0 | ||||||||||||||||||
| 1305 | } | - | ||||||||||||||||||
| 1306 | - | |||||||||||||||||||
| 1307 | /*! | - | ||||||||||||||||||
| 1308 | \since 5.0 | - | ||||||||||||||||||
| 1309 | - | |||||||||||||||||||
| 1310 | Flushes the internal cache of authentication data and network connections. | - | ||||||||||||||||||
| 1311 | - | |||||||||||||||||||
| 1312 | This function is useful for doing auto tests. | - | ||||||||||||||||||
| 1313 | - | |||||||||||||||||||
| 1314 | */ | - | ||||||||||||||||||
| 1315 | void QNetworkAccessManager::clearAccessCache() | - | ||||||||||||||||||
| 1316 | { | - | ||||||||||||||||||
| 1317 | QNetworkAccessManagerPrivate::clearCache(this); | - | ||||||||||||||||||
| 1318 | } executed 644 times by 2 tests: end of blockExecuted by:
| 644 | ||||||||||||||||||
| 1319 | - | |||||||||||||||||||
| 1320 | void QNetworkAccessManagerPrivate::_q_replyFinished() | - | ||||||||||||||||||
| 1321 | { | - | ||||||||||||||||||
| 1322 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1323 | - | |||||||||||||||||||
| 1324 | QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); | - | ||||||||||||||||||
| 1325 | if (reply)
| 0-931 | ||||||||||||||||||
| 1326 | emit q->finished(reply); executed 931 times by 9 tests: q->finished(reply);Executed by:
| 931 | ||||||||||||||||||
| 1327 | - | |||||||||||||||||||
| 1328 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1329 | // If there are no active requests, release our reference to the network session. | - | ||||||||||||||||||
| 1330 | // It will not be destroyed immediately, but rather when the connection cache is flushed | - | ||||||||||||||||||
| 1331 | // after 2 minutes. | - | ||||||||||||||||||
| 1332 | activeReplyCount--; | - | ||||||||||||||||||
| 1333 | if (networkSessionStrongRef && activeReplyCount == 0)
| 11-920 | ||||||||||||||||||
| 1334 | networkSessionStrongRef.clear(); executed 195 times by 7 tests: networkSessionStrongRef.clear();Executed by:
| 195 | ||||||||||||||||||
| 1335 | #endif | - | ||||||||||||||||||
| 1336 | } executed 931 times by 9 tests: end of blockExecuted by:
| 931 | ||||||||||||||||||
| 1337 | - | |||||||||||||||||||
| 1338 | void QNetworkAccessManagerPrivate::_q_replyEncrypted() | - | ||||||||||||||||||
| 1339 | { | - | ||||||||||||||||||
| 1340 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1341 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1342 | QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); | - | ||||||||||||||||||
| 1343 | if (reply)
| 0-75 | ||||||||||||||||||
| 1344 | emit q->encrypted(reply); executed 75 times by 2 tests: q->encrypted(reply);Executed by:
| 75 | ||||||||||||||||||
| 1345 | #endif | - | ||||||||||||||||||
| 1346 | } executed 75 times by 2 tests: end of blockExecuted by:
| 75 | ||||||||||||||||||
| 1347 | - | |||||||||||||||||||
| 1348 | void QNetworkAccessManagerPrivate::_q_replySslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
| 1349 | { | - | ||||||||||||||||||
| 1350 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1351 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1352 | QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); | - | ||||||||||||||||||
| 1353 | if (reply)
| 0-48 | ||||||||||||||||||
| 1354 | emit q->sslErrors(reply, errors); executed 48 times by 2 tests: q->sslErrors(reply, errors);Executed by:
| 48 | ||||||||||||||||||
| 1355 | #else | - | ||||||||||||||||||
| 1356 | Q_UNUSED(errors); | - | ||||||||||||||||||
| 1357 | #endif | - | ||||||||||||||||||
| 1358 | } executed 48 times by 2 tests: end of blockExecuted by:
| 48 | ||||||||||||||||||
| 1359 | - | |||||||||||||||||||
| 1360 | void QNetworkAccessManagerPrivate::_q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator) | - | ||||||||||||||||||
| 1361 | { | - | ||||||||||||||||||
| 1362 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1363 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1364 | QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender()); | - | ||||||||||||||||||
| 1365 | if (reply)
| 0 | ||||||||||||||||||
| 1366 | emit q->preSharedKeyAuthenticationRequired(reply, authenticator); never executed: q->preSharedKeyAuthenticationRequired(reply, authenticator); | 0 | ||||||||||||||||||
| 1367 | #else | - | ||||||||||||||||||
| 1368 | Q_UNUSED(authenticator); | - | ||||||||||||||||||
| 1369 | #endif | - | ||||||||||||||||||
| 1370 | } never executed: end of block | 0 | ||||||||||||||||||
| 1371 | - | |||||||||||||||||||
| 1372 | QNetworkReply *QNetworkAccessManagerPrivate::postProcess(QNetworkReply *reply) | - | ||||||||||||||||||
| 1373 | { | - | ||||||||||||||||||
| 1374 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1375 | QNetworkReplyPrivate::setManager(reply, q); | - | ||||||||||||||||||
| 1376 | q->connect(reply, SIGNAL(finished()), SLOT(_q_replyFinished())); | - | ||||||||||||||||||
| 1377 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
| 1378 | /* In case we're compiled without SSL support, we don't have this signal and we need to | - | ||||||||||||||||||
| 1379 | * avoid getting a connection error. */ | - | ||||||||||||||||||
| 1380 | q->connect(reply, SIGNAL(encrypted()), SLOT(_q_replyEncrypted())); | - | ||||||||||||||||||
| 1381 | q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>))); | - | ||||||||||||||||||
| 1382 | q->connect(reply, SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), SLOT(_q_replyPreSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*))); | - | ||||||||||||||||||
| 1383 | #endif | - | ||||||||||||||||||
| 1384 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1385 | activeReplyCount++; | - | ||||||||||||||||||
| 1386 | #endif | - | ||||||||||||||||||
| 1387 | - | |||||||||||||||||||
| 1388 | return reply; executed 1069 times by 10 tests: return reply;Executed by:
| 1069 | ||||||||||||||||||
| 1389 | } | - | ||||||||||||||||||
| 1390 | - | |||||||||||||||||||
| 1391 | void QNetworkAccessManagerPrivate::createCookieJar() const | - | ||||||||||||||||||
| 1392 | { | - | ||||||||||||||||||
| 1393 | if (!cookieJarCreated) {
| 0 | ||||||||||||||||||
| 1394 | // keep the ugly hack in here | - | ||||||||||||||||||
| 1395 | QNetworkAccessManagerPrivate *that = const_cast<QNetworkAccessManagerPrivate *>(this); | - | ||||||||||||||||||
| 1396 | that->cookieJar = new QNetworkCookieJar(that->q_func()); | - | ||||||||||||||||||
| 1397 | that->cookieJarCreated = true; | - | ||||||||||||||||||
| 1398 | } never executed: end of block | 0 | ||||||||||||||||||
| 1399 | } never executed: end of block | 0 | ||||||||||||||||||
| 1400 | - | |||||||||||||||||||
| 1401 | void QNetworkAccessManagerPrivate::authenticationRequired(QAuthenticator *authenticator, | - | ||||||||||||||||||
| 1402 | QNetworkReply *reply, | - | ||||||||||||||||||
| 1403 | bool synchronous, | - | ||||||||||||||||||
| 1404 | QUrl &url, | - | ||||||||||||||||||
| 1405 | QUrl *urlForLastAuthentication, | - | ||||||||||||||||||
| 1406 | bool allowAuthenticationReuse) | - | ||||||||||||||||||
| 1407 | { | - | ||||||||||||||||||
| 1408 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1409 | - | |||||||||||||||||||
| 1410 | // don't try the cache for the same URL twice in a row | - | ||||||||||||||||||
| 1411 | // being called twice for the same URL means the authentication failed | - | ||||||||||||||||||
| 1412 | // also called when last URL is empty, e.g. on first call | - | ||||||||||||||||||
| 1413 | if (allowAuthenticationReuse && (urlForLastAuthentication->isEmpty()
| 1-126 | ||||||||||||||||||
| 1414 | || url != *urlForLastAuthentication)) {
| 0-38 | ||||||||||||||||||
| 1415 | // if credentials are included in the url, then use them | - | ||||||||||||||||||
| 1416 | if (!url.userName().isEmpty()
| 12-76 | ||||||||||||||||||
| 1417 | && !url.password().isEmpty()) {
| 0-12 | ||||||||||||||||||
| 1418 | authenticator->setUser(url.userName(QUrl::FullyDecoded)); | - | ||||||||||||||||||
| 1419 | authenticator->setPassword(url.password(QUrl::FullyDecoded)); | - | ||||||||||||||||||
| 1420 | *urlForLastAuthentication = url; | - | ||||||||||||||||||
| 1421 | authenticationManager->cacheCredentials(url, authenticator); | - | ||||||||||||||||||
| 1422 | return; executed 12 times by 1 test: return;Executed by:
| 12 | ||||||||||||||||||
| 1423 | } | - | ||||||||||||||||||
| 1424 | - | |||||||||||||||||||
| 1425 | QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedCredentials(url, authenticator); | - | ||||||||||||||||||
| 1426 | if (!cred.isNull()) {
| 20-56 | ||||||||||||||||||
| 1427 | authenticator->setUser(cred.user); | - | ||||||||||||||||||
| 1428 | authenticator->setPassword(cred.password); | - | ||||||||||||||||||
| 1429 | *urlForLastAuthentication = url; | - | ||||||||||||||||||
| 1430 | return; executed 20 times by 1 test: return;Executed by:
| 20 | ||||||||||||||||||
| 1431 | } | - | ||||||||||||||||||
| 1432 | } executed 56 times by 1 test: end of blockExecuted by:
| 56 | ||||||||||||||||||
| 1433 | - | |||||||||||||||||||
| 1434 | // if we emit a signal here in synchronous mode, the user might spin | - | ||||||||||||||||||
| 1435 | // an event loop, which might recurse and lead to problems | - | ||||||||||||||||||
| 1436 | if (synchronous)
| 0-95 | ||||||||||||||||||
| 1437 | return; never executed: return; | 0 | ||||||||||||||||||
| 1438 | - | |||||||||||||||||||
| 1439 | *urlForLastAuthentication = url; | - | ||||||||||||||||||
| 1440 | emit q->authenticationRequired(reply, authenticator); | - | ||||||||||||||||||
| 1441 | if (allowAuthenticationReuse)
| 1-94 | ||||||||||||||||||
| 1442 | authenticationManager->cacheCredentials(url, authenticator); executed 94 times by 1 test: authenticationManager->cacheCredentials(url, authenticator);Executed by:
| 94 | ||||||||||||||||||
| 1443 | } executed 95 times by 1 test: end of blockExecuted by:
| 95 | ||||||||||||||||||
| 1444 | - | |||||||||||||||||||
| 1445 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
| 1446 | void QNetworkAccessManagerPrivate::proxyAuthenticationRequired(const QUrl &url, | - | ||||||||||||||||||
| 1447 | const QNetworkProxy &proxy, | - | ||||||||||||||||||
| 1448 | bool synchronous, | - | ||||||||||||||||||
| 1449 | QAuthenticator *authenticator, | - | ||||||||||||||||||
| 1450 | QNetworkProxy *lastProxyAuthentication) | - | ||||||||||||||||||
| 1451 | { | - | ||||||||||||||||||
| 1452 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1453 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(*authenticator); | - | ||||||||||||||||||
| 1454 | if (proxy != *lastProxyAuthentication && (!priv || !priv->hasFailed)) {
| 2-66 | ||||||||||||||||||
| 1455 | QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedProxyCredentials(proxy); | - | ||||||||||||||||||
| 1456 | if (!cred.isNull()) {
| 8-56 | ||||||||||||||||||
| 1457 | authenticator->setUser(cred.user); | - | ||||||||||||||||||
| 1458 | authenticator->setPassword(cred.password); | - | ||||||||||||||||||
| 1459 | return; executed 8 times by 1 test: return;Executed by:
| 8 | ||||||||||||||||||
| 1460 | } | - | ||||||||||||||||||
| 1461 | } executed 56 times by 2 tests: end of blockExecuted by:
| 56 | ||||||||||||||||||
| 1462 | - | |||||||||||||||||||
| 1463 | #if defined(Q_OS_OSX) | - | ||||||||||||||||||
| 1464 | //now we try to get the username and password from keychain | - | ||||||||||||||||||
| 1465 | //if not successful signal will be emitted | - | ||||||||||||||||||
| 1466 | QString username; | - | ||||||||||||||||||
| 1467 | QString password; | - | ||||||||||||||||||
| 1468 | if (getProxyAuth(proxy.hostName(), url.scheme(), username, password)) { | - | ||||||||||||||||||
| 1469 | // only cache the system credentials if they are correct (or if they have changed) | - | ||||||||||||||||||
| 1470 | // to not run into an endless loop in case they are wrong | - | ||||||||||||||||||
| 1471 | QNetworkAuthenticationCredential cred = authenticationManager->fetchCachedProxyCredentials(proxy); | - | ||||||||||||||||||
| 1472 | if (!priv->hasFailed || cred.user != username || cred.password != password) { | - | ||||||||||||||||||
| 1473 | authenticator->setUser(username); | - | ||||||||||||||||||
| 1474 | authenticator->setPassword(password); | - | ||||||||||||||||||
| 1475 | authenticationManager->cacheProxyCredentials(proxy, authenticator); | - | ||||||||||||||||||
| 1476 | return; | - | ||||||||||||||||||
| 1477 | } | - | ||||||||||||||||||
| 1478 | } | - | ||||||||||||||||||
| 1479 | #else | - | ||||||||||||||||||
| 1480 | Q_UNUSED(url); | - | ||||||||||||||||||
| 1481 | #endif | - | ||||||||||||||||||
| 1482 | - | |||||||||||||||||||
| 1483 | // if we emit a signal here in synchronous mode, the user might spin | - | ||||||||||||||||||
| 1484 | // an event loop, which might recurse and lead to problems | - | ||||||||||||||||||
| 1485 | if (synchronous)
| 0-60 | ||||||||||||||||||
| 1486 | return; never executed: return; | 0 | ||||||||||||||||||
| 1487 | - | |||||||||||||||||||
| 1488 | *lastProxyAuthentication = proxy; | - | ||||||||||||||||||
| 1489 | emit q->proxyAuthenticationRequired(proxy, authenticator); | - | ||||||||||||||||||
| 1490 | authenticationManager->cacheProxyCredentials(proxy, authenticator); | - | ||||||||||||||||||
| 1491 | } executed 60 times by 2 tests: end of blockExecuted by:
| 60 | ||||||||||||||||||
| 1492 | - | |||||||||||||||||||
| 1493 | QList<QNetworkProxy> QNetworkAccessManagerPrivate::queryProxy(const QNetworkProxyQuery &query) | - | ||||||||||||||||||
| 1494 | { | - | ||||||||||||||||||
| 1495 | QList<QNetworkProxy> proxies; | - | ||||||||||||||||||
| 1496 | if (proxyFactory) {
| 20-986 | ||||||||||||||||||
| 1497 | proxies = proxyFactory->queryProxy(query); | - | ||||||||||||||||||
| 1498 | if (proxies.isEmpty()) {
| 0-20 | ||||||||||||||||||
| 1499 | qWarning("QNetworkAccessManager: factory %p has returned an empty result set", | - | ||||||||||||||||||
| 1500 | proxyFactory); | - | ||||||||||||||||||
| 1501 | proxies << QNetworkProxy::NoProxy; | - | ||||||||||||||||||
| 1502 | } never executed: end of block | 0 | ||||||||||||||||||
| 1503 | } else if (proxy.type() == QNetworkProxy::DefaultProxy) { executed 20 times by 1 test: end of blockExecuted by:
| 20-832 | ||||||||||||||||||
| 1504 | // no proxy set, query the application | - | ||||||||||||||||||
| 1505 | return QNetworkProxyFactory::proxyForQuery(query); executed 832 times by 8 tests: return QNetworkProxyFactory::proxyForQuery(query);Executed by:
| 832 | ||||||||||||||||||
| 1506 | } else { | - | ||||||||||||||||||
| 1507 | proxies << proxy; | - | ||||||||||||||||||
| 1508 | } executed 154 times by 2 tests: end of blockExecuted by:
| 154 | ||||||||||||||||||
| 1509 | - | |||||||||||||||||||
| 1510 | return proxies; executed 174 times by 2 tests: return proxies;Executed by:
| 174 | ||||||||||||||||||
| 1511 | } | - | ||||||||||||||||||
| 1512 | #endif | - | ||||||||||||||||||
| 1513 | - | |||||||||||||||||||
| 1514 | void QNetworkAccessManagerPrivate::clearCache(QNetworkAccessManager *manager) | - | ||||||||||||||||||
| 1515 | { | - | ||||||||||||||||||
| 1516 | manager->d_func()->objectCache.clear(); | - | ||||||||||||||||||
| 1517 | manager->d_func()->authenticationManager->clearCache(); | - | ||||||||||||||||||
| 1518 | - | |||||||||||||||||||
| 1519 | if (manager->d_func()->httpThread) {
| 252-394 | ||||||||||||||||||
| 1520 | manager->d_func()->httpThread->quit(); | - | ||||||||||||||||||
| 1521 | manager->d_func()->httpThread->wait(5000); | - | ||||||||||||||||||
| 1522 | if (manager->d_func()->httpThread->isFinished())
| 0-394 | ||||||||||||||||||
| 1523 | delete manager->d_func()->httpThread; executed 394 times by 2 tests: delete manager->d_func()->httpThread;Executed by:
| 394 | ||||||||||||||||||
| 1524 | else | - | ||||||||||||||||||
| 1525 | QObject::connect(manager->d_func()->httpThread, SIGNAL(finished()), manager->d_func()->httpThread, SLOT(deleteLater())); never executed: QObject::connect(manager->d_func()->httpThread, qFlagLocation("2""finished()" "\0" __FILE__ ":" "1525"), manager->d_func()->httpThread, qFlagLocation("1""deleteLater()" "\0" __FILE__ ":" "1525")); | 0 | ||||||||||||||||||
| 1526 | manager->d_func()->httpThread = 0; | - | ||||||||||||||||||
| 1527 | } executed 394 times by 2 tests: end of blockExecuted by:
| 394 | ||||||||||||||||||
| 1528 | } executed 646 times by 2 tests: end of blockExecuted by:
| 646 | ||||||||||||||||||
| 1529 | - | |||||||||||||||||||
| 1530 | QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate() | - | ||||||||||||||||||
| 1531 | { | - | ||||||||||||||||||
| 1532 | if (httpThread) {
| 16-76 | ||||||||||||||||||
| 1533 | httpThread->quit(); | - | ||||||||||||||||||
| 1534 | httpThread->wait(5000); | - | ||||||||||||||||||
| 1535 | if (httpThread->isFinished())
| 0-76 | ||||||||||||||||||
| 1536 | delete httpThread; executed 76 times by 8 tests: delete httpThread;Executed by:
| 76 | ||||||||||||||||||
| 1537 | else | - | ||||||||||||||||||
| 1538 | QObject::connect(httpThread, SIGNAL(finished()), httpThread, SLOT(deleteLater())); never executed: QObject::connect(httpThread, qFlagLocation("2""finished()" "\0" __FILE__ ":" "1538"), httpThread, qFlagLocation("1""deleteLater()" "\0" __FILE__ ":" "1538")); | 0 | ||||||||||||||||||
| 1539 | httpThread = 0; | - | ||||||||||||||||||
| 1540 | } executed 76 times by 8 tests: end of blockExecuted by:
| 76 | ||||||||||||||||||
| 1541 | } executed 92 times by 11 tests: end of blockExecuted by:
| 92 | ||||||||||||||||||
| 1542 | - | |||||||||||||||||||
| 1543 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1544 | void QNetworkAccessManagerPrivate::createSession(const QNetworkConfiguration &config) | - | ||||||||||||||||||
| 1545 | { | - | ||||||||||||||||||
| 1546 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1547 | - | |||||||||||||||||||
| 1548 | initializeSession = false; | - | ||||||||||||||||||
| 1549 | - | |||||||||||||||||||
| 1550 | //resurrect weak ref if possible | - | ||||||||||||||||||
| 1551 | networkSessionStrongRef = networkSessionWeakRef.toStrongRef(); | - | ||||||||||||||||||
| 1552 | - | |||||||||||||||||||
| 1553 | QSharedPointer<QNetworkSession> newSession; | - | ||||||||||||||||||
| 1554 | if (config.isValid())
| 0-222 | ||||||||||||||||||
| 1555 | newSession = QSharedNetworkSessionManager::getSession(config); executed 222 times by 9 tests: newSession = QSharedNetworkSessionManager::getSession(config);Executed by:
| 222 | ||||||||||||||||||
| 1556 | - | |||||||||||||||||||
| 1557 | if (networkSessionStrongRef) {
| 99-123 | ||||||||||||||||||
| 1558 | //do nothing if new and old session are the same | - | ||||||||||||||||||
| 1559 | if (networkSessionStrongRef == newSession)
| 0-123 | ||||||||||||||||||
| 1560 | return; executed 123 times by 3 tests: return;Executed by:
| 123 | ||||||||||||||||||
| 1561 | //disconnect from old session | - | ||||||||||||||||||
| 1562 | QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected())); | - | ||||||||||||||||||
| 1563 | QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed())); | - | ||||||||||||||||||
| 1564 | QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(stateChanged(QNetworkSession::State)), | - | ||||||||||||||||||
| 1565 | q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State))); | - | ||||||||||||||||||
| 1566 | QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(error(QNetworkSession::SessionError)), | - | ||||||||||||||||||
| 1567 | q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError))); | - | ||||||||||||||||||
| 1568 | } never executed: end of block | 0 | ||||||||||||||||||
| 1569 | - | |||||||||||||||||||
| 1570 | //switch to new session (null if config was invalid) | - | ||||||||||||||||||
| 1571 | networkSessionStrongRef = newSession; | - | ||||||||||||||||||
| 1572 | networkSessionWeakRef = networkSessionStrongRef.toWeakRef(); | - | ||||||||||||||||||
| 1573 | - | |||||||||||||||||||
| 1574 | if (!networkSessionStrongRef) {
| 0-99 | ||||||||||||||||||
| 1575 | - | |||||||||||||||||||
| 1576 | if (networkAccessible == QNetworkAccessManager::NotAccessible || !online)
| 0 | ||||||||||||||||||
| 1577 | emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible); never executed: q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible); | 0 | ||||||||||||||||||
| 1578 | else | - | ||||||||||||||||||
| 1579 | emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility); never executed: q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility); | 0 | ||||||||||||||||||
| 1580 | - | |||||||||||||||||||
| 1581 | return; never executed: return; | 0 | ||||||||||||||||||
| 1582 | } | - | ||||||||||||||||||
| 1583 | - | |||||||||||||||||||
| 1584 | //connect to new session | - | ||||||||||||||||||
| 1585 | QObject::connect(networkSessionStrongRef.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()), Qt::QueuedConnection); | - | ||||||||||||||||||
| 1586 | //QueuedConnection is used to avoid deleting the networkSession inside its closed signal | - | ||||||||||||||||||
| 1587 | QObject::connect(networkSessionStrongRef.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()), Qt::QueuedConnection); | - | ||||||||||||||||||
| 1588 | QObject::connect(networkSessionStrongRef.data(), SIGNAL(stateChanged(QNetworkSession::State)), | - | ||||||||||||||||||
| 1589 | q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)), Qt::QueuedConnection); | - | ||||||||||||||||||
| 1590 | QObject::connect(networkSessionStrongRef.data(), SIGNAL(error(QNetworkSession::SessionError)), | - | ||||||||||||||||||
| 1591 | q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError))); | - | ||||||||||||||||||
| 1592 | - | |||||||||||||||||||
| 1593 | _q_networkSessionStateChanged(networkSessionStrongRef->state()); | - | ||||||||||||||||||
| 1594 | } executed 99 times by 9 tests: end of blockExecuted by:
| 99 | ||||||||||||||||||
| 1595 | - | |||||||||||||||||||
| 1596 | void QNetworkAccessManagerPrivate::_q_networkSessionClosed() | - | ||||||||||||||||||
| 1597 | { | - | ||||||||||||||||||
| 1598 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1599 | QSharedPointer<QNetworkSession> networkSession(getNetworkSession()); | - | ||||||||||||||||||
| 1600 | if (networkSession) {
| 0-4 | ||||||||||||||||||
| 1601 | networkConfiguration = networkSession->configuration(); | - | ||||||||||||||||||
| 1602 | - | |||||||||||||||||||
| 1603 | //disconnect from old session | - | ||||||||||||||||||
| 1604 | QObject::disconnect(networkSession.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected())); | - | ||||||||||||||||||
| 1605 | QObject::disconnect(networkSession.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed())); | - | ||||||||||||||||||
| 1606 | QObject::disconnect(networkSession.data(), SIGNAL(stateChanged(QNetworkSession::State)), | - | ||||||||||||||||||
| 1607 | q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State))); | - | ||||||||||||||||||
| 1608 | QObject::disconnect(networkSession.data(), SIGNAL(error(QNetworkSession::SessionError)), | - | ||||||||||||||||||
| 1609 | q, SLOT(_q_networkSessionFailed(QNetworkSession::SessionError))); | - | ||||||||||||||||||
| 1610 | - | |||||||||||||||||||
| 1611 | networkSessionStrongRef.clear(); | - | ||||||||||||||||||
| 1612 | networkSessionWeakRef.clear(); | - | ||||||||||||||||||
| 1613 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 1614 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 1615 | - | |||||||||||||||||||
| 1616 | void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged(QNetworkSession::State state) | - | ||||||||||||||||||
| 1617 | { | - | ||||||||||||||||||
| 1618 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1619 | bool reallyOnline = false; | - | ||||||||||||||||||
| 1620 | //Do not emit the networkSessionConnected signal here, except for roaming -> connected | - | ||||||||||||||||||
| 1621 | //transition, otherwise it is emitted twice in a row when opening a connection. | - | ||||||||||||||||||
| 1622 | if (state == QNetworkSession::Connected && lastSessionState != QNetworkSession::Roaming)
| 0-99 | ||||||||||||||||||
| 1623 | emit q->networkSessionConnected(); executed 99 times by 9 tests: q->networkSessionConnected();Executed by:
| 99 | ||||||||||||||||||
| 1624 | lastSessionState = state; | - | ||||||||||||||||||
| 1625 | - | |||||||||||||||||||
| 1626 | if (online && state == QNetworkSession::Disconnected) {
| 0-99 | ||||||||||||||||||
| 1627 | const auto cfgs = networkConfigurationManager.allConfigurations(); | - | ||||||||||||||||||
| 1628 | for (const QNetworkConfiguration &cfg : cfgs) { | - | ||||||||||||||||||
| 1629 | if (cfg.state().testFlag(QNetworkConfiguration::Active)) {
| 0 | ||||||||||||||||||
| 1630 | reallyOnline = true; | - | ||||||||||||||||||
| 1631 | } never executed: end of block | 0 | ||||||||||||||||||
| 1632 | } never executed: end of block | 0 | ||||||||||||||||||
| 1633 | } else if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) { never executed: end of block
| 0-99 | ||||||||||||||||||
| 1634 | reallyOnline = true; | - | ||||||||||||||||||
| 1635 | } executed 99 times by 9 tests: end of blockExecuted by:
| 99 | ||||||||||||||||||
| 1636 | - | |||||||||||||||||||
| 1637 | if (!reallyOnline) {
| 0-99 | ||||||||||||||||||
| 1638 | if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
| 0 | ||||||||||||||||||
| 1639 | if (networkAccessible != QNetworkAccessManager::NotAccessible) {
| 0 | ||||||||||||||||||
| 1640 | networkAccessible = QNetworkAccessManager::NotAccessible; | - | ||||||||||||||||||
| 1641 | emit q->networkAccessibleChanged(networkAccessible); | - | ||||||||||||||||||
| 1642 | } never executed: end of block | 0 | ||||||||||||||||||
| 1643 | } never executed: end of block | 0 | ||||||||||||||||||
| 1644 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1645 | if (defaultAccessControl)
| 0-99 | ||||||||||||||||||
| 1646 | if (networkAccessible != QNetworkAccessManager::Accessible) {
| 0-99 | ||||||||||||||||||
| 1647 | networkAccessible = QNetworkAccessManager::Accessible; | - | ||||||||||||||||||
| 1648 | emit q->networkAccessibleChanged(networkAccessible); | - | ||||||||||||||||||
| 1649 | } never executed: end of block | 0 | ||||||||||||||||||
| 1650 | } executed 99 times by 9 tests: end of blockExecuted by:
| 99 | ||||||||||||||||||
| 1651 | online = reallyOnline; | - | ||||||||||||||||||
| 1652 | if (online && (state != QNetworkSession::Connected && state != QNetworkSession::Roaming)) {
| 0-99 | ||||||||||||||||||
| 1653 | _q_networkSessionClosed(); | - | ||||||||||||||||||
| 1654 | createSession(q->configuration()); | - | ||||||||||||||||||
| 1655 | } never executed: end of block | 0 | ||||||||||||||||||
| 1656 | } executed 99 times by 9 tests: end of blockExecuted by:
| 99 | ||||||||||||||||||
| 1657 | - | |||||||||||||||||||
| 1658 | void QNetworkAccessManagerPrivate::_q_onlineStateChanged(bool isOnline) | - | ||||||||||||||||||
| 1659 | { | - | ||||||||||||||||||
| 1660 | Q_Q(QNetworkAccessManager); | - | ||||||||||||||||||
| 1661 | - | |||||||||||||||||||
| 1662 | // if the user set a config, we only care whether this one is active. | - | ||||||||||||||||||
| 1663 | // Otherwise, this QNAM is online if there is an online config. | - | ||||||||||||||||||
| 1664 | if (customNetworkConfiguration) {
| 0 | ||||||||||||||||||
| 1665 | online = (networkConfiguration.state() & QNetworkConfiguration::Active); | - | ||||||||||||||||||
| 1666 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1667 | if (online != isOnline) {
| 0 | ||||||||||||||||||
| 1668 | _q_networkSessionClosed(); | - | ||||||||||||||||||
| 1669 | createSession(q->configuration()); | - | ||||||||||||||||||
| 1670 | online = isOnline; | - | ||||||||||||||||||
| 1671 | } never executed: end of block | 0 | ||||||||||||||||||
| 1672 | } never executed: end of block | 0 | ||||||||||||||||||
| 1673 | if (online) {
| 0 | ||||||||||||||||||
| 1674 | if (defaultAccessControl) {
| 0 | ||||||||||||||||||
| 1675 | if (networkAccessible != QNetworkAccessManager::Accessible) {
| 0 | ||||||||||||||||||
| 1676 | networkAccessible = QNetworkAccessManager::Accessible; | - | ||||||||||||||||||
| 1677 | emit q->networkAccessibleChanged(networkAccessible); | - | ||||||||||||||||||
| 1678 | } never executed: end of block | 0 | ||||||||||||||||||
| 1679 | } never executed: end of block | 0 | ||||||||||||||||||
| 1680 | } else { never executed: end of block | 0 | ||||||||||||||||||
| 1681 | if (networkAccessible != QNetworkAccessManager::NotAccessible) {
| 0 | ||||||||||||||||||
| 1682 | networkAccessible = QNetworkAccessManager::NotAccessible; | - | ||||||||||||||||||
| 1683 | emit q->networkAccessibleChanged(networkAccessible); | - | ||||||||||||||||||
| 1684 | } never executed: end of block | 0 | ||||||||||||||||||
| 1685 | } never executed: end of block | 0 | ||||||||||||||||||
| 1686 | } | - | ||||||||||||||||||
| 1687 | - | |||||||||||||||||||
| 1688 | void QNetworkAccessManagerPrivate::_q_configurationChanged(const QNetworkConfiguration &configuration) | - | ||||||||||||||||||
| 1689 | { | - | ||||||||||||||||||
| 1690 | const QString id = configuration.identifier(); | - | ||||||||||||||||||
| 1691 | if (configuration.state().testFlag(QNetworkConfiguration::Active)) {
| 0 | ||||||||||||||||||
| 1692 | if (!onlineConfigurations.contains(id)) {
| 0 | ||||||||||||||||||
| 1693 | - | |||||||||||||||||||
| 1694 | QSharedPointer<QNetworkSession> session(getNetworkSession()); | - | ||||||||||||||||||
| 1695 | if (session) {
| 0 | ||||||||||||||||||
| 1696 | if (online && session->configuration().identifier()
| 0 | ||||||||||||||||||
| 1697 | != networkConfigurationManager.defaultConfiguration().identifier()) {
| 0 | ||||||||||||||||||
| 1698 | - | |||||||||||||||||||
| 1699 | onlineConfigurations.insert(id); | - | ||||||||||||||||||
| 1700 | //this one disconnected but another one is online, | - | ||||||||||||||||||
| 1701 | // close and create new session | - | ||||||||||||||||||
| 1702 | _q_networkSessionClosed(); | - | ||||||||||||||||||
| 1703 | createSession(networkConfigurationManager.defaultConfiguration()); | - | ||||||||||||||||||
| 1704 | } never executed: end of block | 0 | ||||||||||||||||||
| 1705 | } never executed: end of block | 0 | ||||||||||||||||||
| 1706 | } never executed: end of block | 0 | ||||||||||||||||||
| 1707 | - | |||||||||||||||||||
| 1708 | } else if (onlineConfigurations.contains(id)) { never executed: end of block
| 0 | ||||||||||||||||||
| 1709 | //this one is disconnecting | - | ||||||||||||||||||
| 1710 | onlineConfigurations.remove(id); | - | ||||||||||||||||||
| 1711 | if (!onlineConfigurations.isEmpty()) {
| 0 | ||||||||||||||||||
| 1712 | _q_networkSessionClosed(); | - | ||||||||||||||||||
| 1713 | createSession(configuration); | - | ||||||||||||||||||
| 1714 | } never executed: end of block | 0 | ||||||||||||||||||
| 1715 | } never executed: end of block | 0 | ||||||||||||||||||
| 1716 | } never executed: end of block | 0 | ||||||||||||||||||
| 1717 | - | |||||||||||||||||||
| 1718 | - | |||||||||||||||||||
| 1719 | void QNetworkAccessManagerPrivate::_q_networkSessionFailed(QNetworkSession::SessionError) | - | ||||||||||||||||||
| 1720 | { | - | ||||||||||||||||||
| 1721 | const auto cfgs = networkConfigurationManager.allConfigurations(); | - | ||||||||||||||||||
| 1722 | for (const QNetworkConfiguration &cfg : cfgs) { | - | ||||||||||||||||||
| 1723 | if (cfg.state().testFlag(QNetworkConfiguration::Active)) {
| 0 | ||||||||||||||||||
| 1724 | online = true; | - | ||||||||||||||||||
| 1725 | _q_networkSessionClosed(); | - | ||||||||||||||||||
| 1726 | createSession(networkConfigurationManager.defaultConfiguration()); | - | ||||||||||||||||||
| 1727 | return; never executed: return; | 0 | ||||||||||||||||||
| 1728 | } | - | ||||||||||||||||||
| 1729 | } never executed: end of block | 0 | ||||||||||||||||||
| 1730 | } never executed: end of block | 0 | ||||||||||||||||||
| 1731 | - | |||||||||||||||||||
| 1732 | #endif // QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
| 1733 | - | |||||||||||||||||||
| 1734 | QNetworkRequest QNetworkAccessManagerPrivate::prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart) | - | ||||||||||||||||||
| 1735 | { | - | ||||||||||||||||||
| 1736 | // copy the request, we probably need to add some headers | - | ||||||||||||||||||
| 1737 | QNetworkRequest newRequest(request); | - | ||||||||||||||||||
| 1738 | - | |||||||||||||||||||
| 1739 | // add Content-Type header if not there already | - | ||||||||||||||||||
| 1740 | if (!request.header(QNetworkRequest::ContentTypeHeader).isValid()) {
| 2-22 | ||||||||||||||||||
| 1741 | QByteArray contentType; | - | ||||||||||||||||||
| 1742 | contentType.reserve(34 + multiPart->d_func()->boundary.count()); | - | ||||||||||||||||||
| 1743 | contentType += "multipart/"; | - | ||||||||||||||||||
| 1744 | switch (multiPart->d_func()->contentType) { | - | ||||||||||||||||||
| 1745 | case QHttpMultiPart::RelatedType: executed 2 times by 1 test: case QHttpMultiPart::RelatedType:Executed by:
| 2 | ||||||||||||||||||
| 1746 | contentType += "related"; | - | ||||||||||||||||||
| 1747 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||
| 1748 | case QHttpMultiPart::FormDataType: executed 13 times by 2 tests: case QHttpMultiPart::FormDataType:Executed by:
| 13 | ||||||||||||||||||
| 1749 | contentType += "form-data"; | - | ||||||||||||||||||
| 1750 | break; executed 13 times by 2 tests: break;Executed by:
| 13 | ||||||||||||||||||
| 1751 | case QHttpMultiPart::AlternativeType: executed 4 times by 1 test: case QHttpMultiPart::AlternativeType:Executed by:
| 4 | ||||||||||||||||||
| 1752 | contentType += "alternative"; | - | ||||||||||||||||||
| 1753 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||
| 1754 | default: executed 3 times by 1 test: default:Executed by:
| 3 | ||||||||||||||||||
| 1755 | contentType += "mixed"; | - | ||||||||||||||||||
| 1756 | break; executed 3 times by 1 test: break;Executed by:
| 3 | ||||||||||||||||||
| 1757 | } | - | ||||||||||||||||||
| 1758 | // putting the boundary into quotes, recommended in RFC 2046 section 5.1.1 | - | ||||||||||||||||||
| 1759 | contentType += "; boundary=\"" + multiPart->d_func()->boundary + '"'; | - | ||||||||||||||||||
| 1760 | newRequest.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(contentType)); | - | ||||||||||||||||||
| 1761 | } executed 22 times by 2 tests: end of blockExecuted by:
| 22 | ||||||||||||||||||
| 1762 | - | |||||||||||||||||||
| 1763 | // add MIME-Version header if not there already (we must include the header | - | ||||||||||||||||||
| 1764 | // if the message conforms to RFC 2045, see section 4 of that RFC) | - | ||||||||||||||||||
| 1765 | QByteArray mimeHeader("MIME-Version"); | - | ||||||||||||||||||
| 1766 | if (!request.hasRawHeader(mimeHeader))
| 0-24 | ||||||||||||||||||
| 1767 | newRequest.setRawHeader(mimeHeader, QByteArray("1.0")); executed 24 times by 2 tests: newRequest.setRawHeader(mimeHeader, QByteArray("1.0"));Executed by:
| 24 | ||||||||||||||||||
| 1768 | - | |||||||||||||||||||
| 1769 | QIODevice *device = multiPart->d_func()->device; | - | ||||||||||||||||||
| 1770 | if (!device->isReadable()) {
| 0-24 | ||||||||||||||||||
| 1771 | if (!device->isOpen()) {
| 0-24 | ||||||||||||||||||
| 1772 | if (!device->open(QIODevice::ReadOnly))
| 0-24 | ||||||||||||||||||
| 1773 | qWarning("could not open device for reading"); never executed: QMessageLogger(__FILE__, 1773, __PRETTY_FUNCTION__).warning("could not open device for reading"); | 0 | ||||||||||||||||||
| 1774 | } else { executed 24 times by 2 tests: end of blockExecuted by:
| 24 | ||||||||||||||||||
| 1775 | qWarning("device is not readable"); | - | ||||||||||||||||||
| 1776 | } never executed: end of block | 0 | ||||||||||||||||||
| 1777 | } | - | ||||||||||||||||||
| 1778 | - | |||||||||||||||||||
| 1779 | return newRequest; executed 24 times by 2 tests: return newRequest;Executed by:
| 24 | ||||||||||||||||||
| 1780 | } | - | ||||||||||||||||||
| 1781 | - | |||||||||||||||||||
| 1782 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 1783 | - | |||||||||||||||||||
| 1784 | #include "moc_qnetworkaccessmanager.cpp" | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |