| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qhttpnetworkconnectionchannel.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | - | |||||||||||||||||||
| 13 | - | |||||||||||||||||||
| 14 | - | |||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | static const int reconnectAttemptsDefault = 3; | - | ||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel() | - | ||||||||||||||||||
| 22 | : socket(0) | - | ||||||||||||||||||
| 23 | , ssl(false) | - | ||||||||||||||||||
| 24 | , isInitialized(false) | - | ||||||||||||||||||
| 25 | , state(IdleState) | - | ||||||||||||||||||
| 26 | , reply(0) | - | ||||||||||||||||||
| 27 | , written(0) | - | ||||||||||||||||||
| 28 | , bytesTotal(0) | - | ||||||||||||||||||
| 29 | , resendCurrent(false) | - | ||||||||||||||||||
| 30 | , lastStatus(0) | - | ||||||||||||||||||
| 31 | , pendingEncrypt(false) | - | ||||||||||||||||||
| 32 | , reconnectAttempts(reconnectAttemptsDefault) | - | ||||||||||||||||||
| 33 | , authMethod(QAuthenticatorPrivate::None) | - | ||||||||||||||||||
| 34 | , proxyAuthMethod(QAuthenticatorPrivate::None) | - | ||||||||||||||||||
| 35 | , authenticationCredentialsSent(false) | - | ||||||||||||||||||
| 36 | , proxyCredentialsSent(false) | - | ||||||||||||||||||
| 37 | , protocolHandler(0) | - | ||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | , ignoreAllSslErrors(false) | - | ||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | , pipeliningSupported(PipeliningSupportUnknown) | - | ||||||||||||||||||
| 42 | , networkLayerPreference(QAbstractSocket::AnyIPProtocol) | - | ||||||||||||||||||
| 43 | , connection(0) | - | ||||||||||||||||||
| 44 | { | - | ||||||||||||||||||
| 45 | - | |||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | } | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | void QHttpNetworkConnectionChannel::init() | - | ||||||||||||||||||
| 50 | { | - | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | if (connection->d_func()->encrypt) | - | ||||||||||||||||||
| 53 | socket = new QSslSocket; | - | ||||||||||||||||||
| 54 | else | - | ||||||||||||||||||
| 55 | socket = new QTcpSocket; | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | if (networkSession) | - | ||||||||||||||||||
| 62 | socket->setProperty("_q_networksession", QVariant::fromValue(networkSession)); | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | - | |||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | socket->setProxy(QNetworkProxy::NoProxy); | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | - | |||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | QObject::connect(socket, qFlagLocation("2""bytesWritten(qint64)" "\0" __FILE__ ":" "117""123"), | - | ||||||||||||||||||
| 73 | this, qFlagLocation("1""_q_bytesWritten(qint64)" "\0" __FILE__ ":" "118""124"), | - | ||||||||||||||||||
| 74 | Qt::DirectConnection); | - | ||||||||||||||||||
| 75 | QObject::connect(socket, qFlagLocation("2""connected()" "\0" __FILE__ ":" "120""126"), | - | ||||||||||||||||||
| 76 | this, qFlagLocation("1""_q_connected()" "\0" __FILE__ ":" "121""127"), | - | ||||||||||||||||||
| 77 | Qt::DirectConnection); | - | ||||||||||||||||||
| 78 | QObject::connect(socket, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "123""129"), | - | ||||||||||||||||||
| 79 | this, qFlagLocation("1""_q_readyRead()" "\0" __FILE__ ":" "124""130"), | - | ||||||||||||||||||
| 80 | Qt::DirectConnection); | - | ||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | - | |||||||||||||||||||
| 84 | - | |||||||||||||||||||
| 85 | - | |||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | qRegisterMetaType<QAbstractSocket::SocketError>(); | - | ||||||||||||||||||
| 89 | QObject::connect(socket, qFlagLocation("2""disconnected()" "\0" __FILE__ ":" "134""140"), | - | ||||||||||||||||||
| 90 | this, qFlagLocation("1""_q_disconnected()" "\0" __FILE__ ":" "135""141"), | - | ||||||||||||||||||
| 91 | Qt::DirectConnection); | - | ||||||||||||||||||
| 92 | QObject::connect(socket, qFlagLocation("2""error(QAbstractSocket::SocketError)" "\0" __FILE__ ":" "137""143"), | - | ||||||||||||||||||
| 93 | this, qFlagLocation("1""_q_error(QAbstractSocket::SocketError)" "\0" __FILE__ ":" "138""144"), | - | ||||||||||||||||||
| 94 | Qt::DirectConnection); | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | QObject::connect(socket, qFlagLocation("2""proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)" "\0" __FILE__ ":" "143""149"), | - | ||||||||||||||||||
| 99 | this, qFlagLocation("1""_q_proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)" "\0" __FILE__ ":" "144""150"), | - | ||||||||||||||||||
| 100 | Qt::DirectConnection); | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | - | |||||||||||||||||||
| 103 | - | |||||||||||||||||||
| 104 | QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); | - | ||||||||||||||||||
| 105 | if (sslSocket) { | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | QObject::connect(sslSocket, qFlagLocation("2""encrypted()" "\0" __FILE__ ":" "152""158"), | - | ||||||||||||||||||
| 108 | this, qFlagLocation("1""_q_encrypted()" "\0" __FILE__ ":" "153""159"), | - | ||||||||||||||||||
| 109 | Qt::DirectConnection); | - | ||||||||||||||||||
| 110 | QObject::connect(sslSocket, qFlagLocation("2""sslErrors(QList<QSslError>)" "\0" __FILE__ ":" "155""161"), | - | ||||||||||||||||||
| 111 | this, qFlagLocation("1""_q_sslErrors(QList<QSslError>)" "\0" __FILE__ ":" "156""162"), | - | ||||||||||||||||||
| 112 | Qt::DirectConnection); | - | ||||||||||||||||||
| 113 | QObject::connect(sslSocket, qFlagLocation("2""preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)" "\0" __FILE__ ":" "158""164"), | - | ||||||||||||||||||
| 114 | this, qFlagLocation("1""_q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)" "\0" __FILE__ ":" "159""165"), | - | ||||||||||||||||||
| 115 | Qt::DirectConnection); | - | ||||||||||||||||||
| 116 | QObject::connect(sslSocket, qFlagLocation("2""encryptedBytesWritten(qint64)" "\0" __FILE__ ":" "161""167"), | - | ||||||||||||||||||
| 117 | this, qFlagLocation("1""_q_encryptedBytesWritten(qint64)" "\0" __FILE__ ":" "162""168"), | - | ||||||||||||||||||
| 118 | Qt::DirectConnection); | - | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | if (ignoreAllSslErrors) | - | ||||||||||||||||||
| 121 | sslSocket->ignoreSslErrors(); | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | if (!ignoreSslErrorsList.isEmpty()) | - | ||||||||||||||||||
| 124 | sslSocket->ignoreSslErrors(ignoreSslErrorsList); | - | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | if (!sslConfiguration.isNull()) | - | ||||||||||||||||||
| 127 | sslSocket->setSslConfiguration(sslConfiguration); | - | ||||||||||||||||||
| 128 | } else { | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | protocolHandler.reset(new QHttpProtocolHandler(this)); | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | } | - | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | if (proxy.type() != QNetworkProxy::NoProxy) | - | ||||||||||||||||||
| 137 | socket->setProxy(proxy); | - | ||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | isInitialized = true; | - | ||||||||||||||||||
| 140 | } | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | - | |||||||||||||||||||
| 143 | void QHttpNetworkConnectionChannel::close() | - | ||||||||||||||||||
| 144 | { | - | ||||||||||||||||||
| 145 | if (!socket) | - | ||||||||||||||||||
| 146 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 147 | else if (socket->state() == QAbstractSocket::UnconnectedState) | - | ||||||||||||||||||
| 148 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 149 | else | - | ||||||||||||||||||
| 150 | state = QHttpNetworkConnectionChannel::ClosingState; | - | ||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | pendingEncrypt = false; | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | if (socket) { | - | ||||||||||||||||||
| 156 | - | |||||||||||||||||||
| 157 | - | |||||||||||||||||||
| 158 | socket->close(); | - | ||||||||||||||||||
| 159 | } | - | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | - | |||||||||||||||||||
| 163 | void QHttpNetworkConnectionChannel::abort() | - | ||||||||||||||||||
| 164 | { | - | ||||||||||||||||||
| 165 | if (!socket) | - | ||||||||||||||||||
| 166 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 167 | else if (socket->state() == QAbstractSocket::UnconnectedState) | - | ||||||||||||||||||
| 168 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 169 | else | - | ||||||||||||||||||
| 170 | state = QHttpNetworkConnectionChannel::ClosingState; | - | ||||||||||||||||||
| 171 | - | |||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | pendingEncrypt = false; | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | if (socket) { | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | socket->abort(); | - | ||||||||||||||||||
| 179 | } | - | ||||||||||||||||||
| 180 | } | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | bool QHttpNetworkConnectionChannel::sendRequest() | - | ||||||||||||||||||
| 184 | { | - | ||||||||||||||||||
| 185 | ((!(!protocolHandler.isNull())) ? qt_assert("!protocolHandler.isNull()",__FILE__,230236) : qt_noop()); | - | ||||||||||||||||||
| 186 | return protocolHandler->sendRequest(); | - | ||||||||||||||||||
| 187 | } | - | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | void QHttpNetworkConnectionChannel::_q_receiveReply() | - | ||||||||||||||||||
| 191 | { | - | ||||||||||||||||||
| 192 | ((!(!protocolHandler.isNull())) ? qt_assert("!protocolHandler.isNull()",__FILE__,237243) : qt_noop()); | - | ||||||||||||||||||
| 193 | protocolHandler->_q_receiveReply(); | - | ||||||||||||||||||
| 194 | } | - | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | void QHttpNetworkConnectionChannel::_q_readyRead() | - | ||||||||||||||||||
| 197 | { | - | ||||||||||||||||||
| 198 | ((!(!protocolHandler.isNull())) ? qt_assert("!protocolHandler.isNull()",__FILE__,243249) : qt_noop()); | - | ||||||||||||||||||
| 199 | protocolHandler->_q_readyRead(); | - | ||||||||||||||||||
| 200 | } | - | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | void QHttpNetworkConnectionChannel::handleUnexpectedEOF() | - | ||||||||||||||||||
| 204 | { | - | ||||||||||||||||||
| 205 | ((!(reply)) ? qt_assert("reply",__FILE__,250256) : qt_noop()); | - | ||||||||||||||||||
| 206 | if (reconnectAttempts <= 0) { | - | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 209 | close(); | - | ||||||||||||||||||
| 210 | reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::RemoteHostClosedError, socket); | - | ||||||||||||||||||
| 211 | reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString); | - | ||||||||||||||||||
| 212 | reply = 0; | - | ||||||||||||||||||
| 213 | if (protocolHandler) | - | ||||||||||||||||||
| 214 | protocolHandler->setReply(0); | - | ||||||||||||||||||
| 215 | request = QHttpNetworkRequest(); | - | ||||||||||||||||||
| 216 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 217 | } else { | - | ||||||||||||||||||
| 218 | reconnectAttempts--; | - | ||||||||||||||||||
| 219 | reply->d_func()->clear(); | - | ||||||||||||||||||
| 220 | reply->d_func()->connection = connection; | - | ||||||||||||||||||
| 221 | reply->d_func()->connectionChannel = this; | - | ||||||||||||||||||
| 222 | closeAndResendCurrentRequest(); | - | ||||||||||||||||||
| 223 | } | - | ||||||||||||||||||
| 224 | } | - | ||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | bool QHttpNetworkConnectionChannel::ensureConnection() | - | ||||||||||||||||||
| 227 | { | - | ||||||||||||||||||
| 228 | if (!isInitialized) | - | ||||||||||||||||||
| 229 | init(); | - | ||||||||||||||||||
| 230 | - | |||||||||||||||||||
| 231 | QAbstractSocket::SocketState socketState = socket->state(); | - | ||||||||||||||||||
| 232 | - | |||||||||||||||||||
| 233 | - | |||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | - | |||||||||||||||||||
| 237 | - | |||||||||||||||||||
| 238 | if (socketState == QAbstractSocket::ClosingState || | - | ||||||||||||||||||
| 239 | (socketState != QAbstractSocket::UnconnectedState && !socket->isOpen())) { | - | ||||||||||||||||||
| 240 | if (reply) | - | ||||||||||||||||||
| 241 | resendCurrent = true; | - | ||||||||||||||||||
| 242 | return false; | - | ||||||||||||||||||
| 243 | } | - | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | - | |||||||||||||||||||
| 246 | if (socketState == QAbstractSocket::HostLookupState || | - | ||||||||||||||||||
| 247 | socketState == QAbstractSocket::ConnectingState) { | - | ||||||||||||||||||
| 248 | return false; | - | ||||||||||||||||||
| 249 | } | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | - | |||||||||||||||||||
| 253 | if (socketState != QAbstractSocket::ConnectedState) { | - | ||||||||||||||||||
| 254 | - | |||||||||||||||||||
| 255 | state = QHttpNetworkConnectionChannel::ConnectingState; | - | ||||||||||||||||||
| 256 | pendingEncrypt = ssl; | - | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | - | |||||||||||||||||||
| 259 | pipeliningSupported = PipeliningSupportUnknown; | - | ||||||||||||||||||
| 260 | authenticationCredentialsSent = false; | - | ||||||||||||||||||
| 261 | proxyCredentialsSent = false; | - | ||||||||||||||||||
| 262 | authenticator.detach(); | - | ||||||||||||||||||
| 263 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(authenticator); | - | ||||||||||||||||||
| 264 | priv->hasFailed = false; | - | ||||||||||||||||||
| 265 | proxyAuthenticator.detach(); | - | ||||||||||||||||||
| 266 | priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator); | - | ||||||||||||||||||
| 267 | priv->hasFailed = false; | - | ||||||||||||||||||
| 268 | - | |||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | - | |||||||||||||||||||
| 275 | priv = QAuthenticatorPrivate::getPrivate(authenticator); | - | ||||||||||||||||||
| 276 | if (priv && priv->phase == QAuthenticatorPrivate::Done) | - | ||||||||||||||||||
| 277 | priv->phase = QAuthenticatorPrivate::Start; | - | ||||||||||||||||||
| 278 | priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator); | - | ||||||||||||||||||
| 279 | if (priv && priv->phase == QAuthenticatorPrivate::Done) | - | ||||||||||||||||||
| 280 | priv->phase = QAuthenticatorPrivate::Start; | - | ||||||||||||||||||
| 281 | - | |||||||||||||||||||
| 282 | QString connectHost = connection->d_func()->hostName; | - | ||||||||||||||||||
| 283 | quint16 connectPort = connection->d_func()->port; | - | ||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | - | |||||||||||||||||||
| 286 | - | |||||||||||||||||||
| 287 | if (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy && !ssl) { | - | ||||||||||||||||||
| 288 | connectHost = connection->d_func()->networkProxy.hostName(); | - | ||||||||||||||||||
| 289 | connectPort = connection->d_func()->networkProxy.port(); | - | ||||||||||||||||||
| 290 | } | - | ||||||||||||||||||
| 291 | if (socket->proxy().type() == QNetworkProxy::HttpProxy) { | - | ||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | QByteArray value; | - | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | if (request.url().isEmpty()) | - | ||||||||||||||||||
| 296 | value = connection->d_func()->predictNextRequest().headerField("user-agent"); | - | ||||||||||||||||||
| 297 | else | - | ||||||||||||||||||
| 298 | value = request.headerField("user-agent"); | - | ||||||||||||||||||
| 299 | if (!value.isEmpty()) { | - | ||||||||||||||||||
| 300 | QNetworkProxy proxy(socket->proxy()); | - | ||||||||||||||||||
| 301 | proxy.setRawHeader("User-Agent", value); | - | ||||||||||||||||||
| 302 | socket->setProxy(proxy); | - | ||||||||||||||||||
| 303 | } | - | ||||||||||||||||||
| 304 | } | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | if (ssl) { | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); | - | ||||||||||||||||||
| 309 | - | |||||||||||||||||||
| 310 | - | |||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | - | |||||||||||||||||||
| 313 | if (!connection->sslContext().isNull()) | - | ||||||||||||||||||
| 314 | QSslSocketPrivate::checkSettingSslContext(sslSocket, connection->sslContext()); | - | ||||||||||||||||||
| 315 | - | |||||||||||||||||||
| 316 | sslSocket->connectToHostEncrypted(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); | - | ||||||||||||||||||
| 317 | if (ignoreAllSslErrors) | - | ||||||||||||||||||
| 318 | sslSocket->ignoreSslErrors(); | - | ||||||||||||||||||
| 319 | sslSocket->ignoreSslErrors(ignoreSslErrorsList); | - | ||||||||||||||||||
| 320 | - | |||||||||||||||||||
| 321 | - | |||||||||||||||||||
| 322 | - | |||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | socket->setReadBufferSize(64*1024); | - | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | - | |||||||||||||||||||
| 327 | - | |||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | - | |||||||||||||||||||
| 330 | - | |||||||||||||||||||
| 331 | } else { | - | ||||||||||||||||||
| 332 | - | |||||||||||||||||||
| 333 | - | |||||||||||||||||||
| 334 | if (connection->d_func()->networkProxy.type() == QNetworkProxy::NoProxy | - | ||||||||||||||||||
| 335 | && connection->cacheProxy().type() == QNetworkProxy::NoProxy | - | ||||||||||||||||||
| 336 | && connection->transparentProxy().type() == QNetworkProxy::NoProxy) { | - | ||||||||||||||||||
| 337 | - | |||||||||||||||||||
| 338 | socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite | QIODevice::Unbuffered, networkLayerPreference); | - | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | socket->setReadBufferSize(1*1024); | - | ||||||||||||||||||
| 341 | - | |||||||||||||||||||
| 342 | } else { | - | ||||||||||||||||||
| 343 | socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); | - | ||||||||||||||||||
| 344 | - | |||||||||||||||||||
| 345 | - | |||||||||||||||||||
| 346 | - | |||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | socket->setReadBufferSize(64*1024); | - | ||||||||||||||||||
| 349 | } | - | ||||||||||||||||||
| 350 | - | |||||||||||||||||||
| 351 | } | - | ||||||||||||||||||
| 352 | return false; | - | ||||||||||||||||||
| 353 | } | - | ||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | - | |||||||||||||||||||
| 356 | if (pendingEncrypt) { | - | ||||||||||||||||||
| 357 | - | |||||||||||||||||||
| 358 | - | |||||||||||||||||||
| 359 | return false; | - | ||||||||||||||||||
| 360 | } | - | ||||||||||||||||||
| 361 | - | |||||||||||||||||||
| 362 | return true; | - | ||||||||||||||||||
| 363 | } | - | ||||||||||||||||||
| 364 | - | |||||||||||||||||||
| 365 | void QHttpNetworkConnectionChannel::allDone() | - | ||||||||||||||||||
| 366 | { | - | ||||||||||||||||||
| 367 | ((!(reply)) ? qt_assert("reply",__FILE__,412418) : qt_noop()); | - | ||||||||||||||||||
| 368 | - | |||||||||||||||||||
| 369 | if (!reply
| 0-1762 | ||||||||||||||||||
| 370 | QMessageLogger(__FILE__, 415421, __PRETTY_FUNCTION__).warning() << ("QHttpNetworkConnectionChannel::allDone() called without reply. Please report at http://bugreports.qt.io/";); | - | ||||||||||||||||||
| 371 | return; never executed: return; | 0 | ||||||||||||||||||
| 372 | } | - | ||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | - | |||||||||||||||||||
| 375 | bool emitFinished = reply->d_func()->shouldEmitSignals(); | - | ||||||||||||||||||
| 376 | bool connectionCloseEnabled = reply->d_func()->isConnectionCloseEnabled(); | - | ||||||||||||||||||
| 377 | detectPipeliningSupport(); | - | ||||||||||||||||||
| 378 | - | |||||||||||||||||||
| 379 | handleStatus(); | - | ||||||||||||||||||
| 380 | - | |||||||||||||||||||
| 381 | - | |||||||||||||||||||
| 382 | - | |||||||||||||||||||
| 383 | - | |||||||||||||||||||
| 384 | - | |||||||||||||||||||
| 385 | if (reply
| 2-1760 | ||||||||||||||||||
| 386 | QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection); executed 1405 times by 7 tests: QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection);Executed by:
| 1405 | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | - | |||||||||||||||||||
| 390 | - | |||||||||||||||||||
| 391 | reconnectAttempts = reconnectAttemptsDefault; | - | ||||||||||||||||||
| 392 | - | |||||||||||||||||||
| 393 | - | |||||||||||||||||||
| 394 | if (state != QHttpNetworkConnectionChannel::ClosingState
| 0-1762 | ||||||||||||||||||
| 395 | state = QHttpNetworkConnectionChannel::IdleState; executed 1762 times by 7 tests: state = QHttpNetworkConnectionChannel::IdleState;Executed by:
| 1762 | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | - | |||||||||||||||||||
| 398 | - | |||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | - | |||||||||||||||||||
| 401 | - | |||||||||||||||||||
| 402 | if (!resendCurrent
| 325-1437 | ||||||||||||||||||
| 403 | request = QHttpNetworkRequest(); | - | ||||||||||||||||||
| 404 | reply = 0; | - | ||||||||||||||||||
| 405 | protocolHandler->setReply(0); | - | ||||||||||||||||||
| 406 | } executed 1437 times by 7 tests: end of blockExecuted by:
| 1437 | ||||||||||||||||||
| 407 | - | |||||||||||||||||||
| 408 | - | |||||||||||||||||||
| 409 | if (!alreadyPipelinedRequests.isEmpty()
| 402-1360 | ||||||||||||||||||
| 410 | if (resendCurrent
| 0-402 | ||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 413 | close(); | - | ||||||||||||||||||
| 414 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 415 | - | |||||||||||||||||||
| 416 | HttpMessagePair messagePair = alreadyPipelinedRequests.takeFirst(); | - | ||||||||||||||||||
| 417 | - | |||||||||||||||||||
| 418 | request = messagePair.first; | - | ||||||||||||||||||
| 419 | reply = messagePair.second; | - | ||||||||||||||||||
| 420 | protocolHandler->setReply(messagePair.second); | - | ||||||||||||||||||
| 421 | state = QHttpNetworkConnectionChannel::ReadingState; | - | ||||||||||||||||||
| 422 | resendCurrent = false; | - | ||||||||||||||||||
| 423 | - | |||||||||||||||||||
| 424 | written = 0; | - | ||||||||||||||||||
| 425 | bytesTotal = 0; | - | ||||||||||||||||||
| 426 | - | |||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | connection->d_func()->fillPipeline(socket); | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | - | |||||||||||||||||||
| 431 | - | |||||||||||||||||||
| 432 | - | |||||||||||||||||||
| 433 | } executed 402 times by 2 tests: end of blockExecuted by:
| 402 | ||||||||||||||||||
| 434 | } else if (alreadyPipelinedRequests.isEmpty()
| 0-1360 | ||||||||||||||||||
| 435 | - | |||||||||||||||||||
| 436 | close(); | - | ||||||||||||||||||
| 437 | - | |||||||||||||||||||
| 438 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 439 | } never executed: else if (alreadyPipelinedRequests.isEmpty()end of block
| 0-1360 | ||||||||||||||||||
| 440 | if (connectionCloseEnabled
| 185-1175 | ||||||||||||||||||
| 441 | if (socket->state() != QAbstractSocket::UnconnectedState
| 60-125 | ||||||||||||||||||
| 442 | close(); executed 125 times by 2 tests: close();Executed by:
| 125 | ||||||||||||||||||
| 443 | if (qobject_cast<QHttpNetworkConnection*>(connection)
| 0-1360 | ||||||||||||||||||
| 444 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 1360 times by 7 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);Executed by:
| 1360 | ||||||||||||||||||
| 445 | } executed 1360 times by 7 tests: end of blockExecuted by:
| 1360 | ||||||||||||||||||
| 446 | } executed 1762 times by 7 tests: end of blockExecuted by:
| 1762 | ||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | void QHttpNetworkConnectionChannel::detectPipeliningSupport() | - | ||||||||||||||||||
| 449 | { | - | ||||||||||||||||||
| 450 | ((!(reply)) ? qt_assert("reply",__FILE__,495501) : qt_noop()); | - | ||||||||||||||||||
| 451 | - | |||||||||||||||||||
| 452 | QByteArray serverHeaderField; | - | ||||||||||||||||||
| 453 | if ( | - | ||||||||||||||||||
| 454 | - | |||||||||||||||||||
| 455 | (reply->d_func()->majorVersion == 1 && reply->d_func()->minorVersion == 1) | - | ||||||||||||||||||
| 456 | - | |||||||||||||||||||
| 457 | && (!reply->d_func()->isConnectionCloseEnabled()) | - | ||||||||||||||||||
| 458 | - | |||||||||||||||||||
| 459 | && (socket->state() == QAbstractSocket::ConnectedState) | - | ||||||||||||||||||
| 460 | - | |||||||||||||||||||
| 461 | - | |||||||||||||||||||
| 462 | && (serverHeaderField = reply->headerField("Server"), !serverHeaderField.contains("Microsoft-IIS/4.")) | - | ||||||||||||||||||
| 463 | && (!serverHeaderField.contains("Microsoft-IIS/5.")) | - | ||||||||||||||||||
| 464 | && (!serverHeaderField.contains("Netscape-Enterprise/3.")) | - | ||||||||||||||||||
| 465 | - | |||||||||||||||||||
| 466 | && (!serverHeaderField.contains("WebLogic")) | - | ||||||||||||||||||
| 467 | && (!serverHeaderField.startsWith("Rocket")) | - | ||||||||||||||||||
| 468 | ) { | - | ||||||||||||||||||
| 469 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningProbablySupported; | - | ||||||||||||||||||
| 470 | } else { | - | ||||||||||||||||||
| 471 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown; | - | ||||||||||||||||||
| 472 | } | - | ||||||||||||||||||
| 473 | } | - | ||||||||||||||||||
| 474 | - | |||||||||||||||||||
| 475 | - | |||||||||||||||||||
| 476 | void QHttpNetworkConnectionChannel::requeueCurrentlyPipelinedRequests() | - | ||||||||||||||||||
| 477 | { | - | ||||||||||||||||||
| 478 | for (int i = 0; i < alreadyPipelinedRequests.length(); i++) | - | ||||||||||||||||||
| 479 | connection->d_func()->requeueRequest(alreadyPipelinedRequests.at(i)); | - | ||||||||||||||||||
| 480 | alreadyPipelinedRequests.clear(); | - | ||||||||||||||||||
| 481 | - | |||||||||||||||||||
| 482 | - | |||||||||||||||||||
| 483 | - | |||||||||||||||||||
| 484 | - | |||||||||||||||||||
| 485 | if (qobject_cast<QHttpNetworkConnection*>(connection)) | - | ||||||||||||||||||
| 486 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 487 | } | - | ||||||||||||||||||
| 488 | - | |||||||||||||||||||
| 489 | void QHttpNetworkConnectionChannel::handleStatus() | - | ||||||||||||||||||
| 490 | { | - | ||||||||||||||||||
| 491 | ((!(socket)) ? qt_assert("socket",__FILE__,536542) : qt_noop()); | - | ||||||||||||||||||
| 492 | ((!(reply)) ? qt_assert("reply",__FILE__,537543) : qt_noop()); | - | ||||||||||||||||||
| 493 | - | |||||||||||||||||||
| 494 | int statusCode = reply->statusCode(); | - | ||||||||||||||||||
| 495 | bool resend = false; | - | ||||||||||||||||||
| 496 | - | |||||||||||||||||||
| 497 | switch (statusCode) { | - | ||||||||||||||||||
| 498 | case 301: | - | ||||||||||||||||||
| 499 | case 302: | - | ||||||||||||||||||
| 500 | case 303: | - | ||||||||||||||||||
| 501 | case 305: | - | ||||||||||||||||||
| 502 | case 307: { | - | ||||||||||||||||||
| 503 | - | |||||||||||||||||||
| 504 | QUrl redirectUrl = connection->d_func()->parseRedirectResponse(socket, reply); | - | ||||||||||||||||||
| 505 | if (redirectUrl.isValid()) | - | ||||||||||||||||||
| 506 | reply->setRedirectUrl(redirectUrl); | - | ||||||||||||||||||
| 507 | - | |||||||||||||||||||
| 508 | if (qobject_cast<QHttpNetworkConnection *>(connection)) | - | ||||||||||||||||||
| 509 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 510 | break; | - | ||||||||||||||||||
| 511 | } | - | ||||||||||||||||||
| 512 | case 401: | - | ||||||||||||||||||
| 513 | case 407: | - | ||||||||||||||||||
| 514 | if (connection->d_func()->handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)) { | - | ||||||||||||||||||
| 515 | if (resend) { | - | ||||||||||||||||||
| 516 | if (!resetUploadData()) | - | ||||||||||||||||||
| 517 | break; | - | ||||||||||||||||||
| 518 | - | |||||||||||||||||||
| 519 | reply->d_func()->eraseData(); | - | ||||||||||||||||||
| 520 | - | |||||||||||||||||||
| 521 | if (alreadyPipelinedRequests.isEmpty()) { | - | ||||||||||||||||||
| 522 | - | |||||||||||||||||||
| 523 | resendCurrent = true; | - | ||||||||||||||||||
| 524 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 525 | } else { | - | ||||||||||||||||||
| 526 | - | |||||||||||||||||||
| 527 | closeAndResendCurrentRequest(); | - | ||||||||||||||||||
| 528 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 529 | } | - | ||||||||||||||||||
| 530 | } else { | - | ||||||||||||||||||
| 531 | - | |||||||||||||||||||
| 532 | close(); | - | ||||||||||||||||||
| 533 | } | - | ||||||||||||||||||
| 534 | } else { | - | ||||||||||||||||||
| 535 | reply->headerChanged(); | - | ||||||||||||||||||
| 536 | reply->readyRead(); | - | ||||||||||||||||||
| 537 | QNetworkReply::NetworkError errorCode = (statusCode == 407) | - | ||||||||||||||||||
| 538 | ? QNetworkReply::ProxyAuthenticationRequiredError | - | ||||||||||||||||||
| 539 | : QNetworkReply::AuthenticationRequiredError; | - | ||||||||||||||||||
| 540 | reply->d_func()->errorString = connection->d_func()->errorDetail(errorCode, socket); | - | ||||||||||||||||||
| 541 | reply->finishedWithError(errorCode, reply->d_func()->errorString); | - | ||||||||||||||||||
| 542 | } | - | ||||||||||||||||||
| 543 | break; | - | ||||||||||||||||||
| 544 | default: | - | ||||||||||||||||||
| 545 | if (qobject_cast<QHttpNetworkConnection*>(connection)) | - | ||||||||||||||||||
| 546 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 547 | } | - | ||||||||||||||||||
| 548 | } | - | ||||||||||||||||||
| 549 | - | |||||||||||||||||||
| 550 | bool QHttpNetworkConnectionChannel::resetUploadData() | - | ||||||||||||||||||
| 551 | { | - | ||||||||||||||||||
| 552 | if (!reply) { | - | ||||||||||||||||||
| 553 | - | |||||||||||||||||||
| 554 | return false; | - | ||||||||||||||||||
| 555 | } | - | ||||||||||||||||||
| 556 | QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); | - | ||||||||||||||||||
| 557 | if (!uploadByteDevice) | - | ||||||||||||||||||
| 558 | return true; | - | ||||||||||||||||||
| 559 | - | |||||||||||||||||||
| 560 | if (uploadByteDevice->reset()) { | - | ||||||||||||||||||
| 561 | written = 0; | - | ||||||||||||||||||
| 562 | return true; | - | ||||||||||||||||||
| 563 | } else { | - | ||||||||||||||||||
| 564 | connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ContentReSendError); | - | ||||||||||||||||||
| 565 | return false; | - | ||||||||||||||||||
| 566 | } | - | ||||||||||||||||||
| 567 | } | - | ||||||||||||||||||
| 568 | - | |||||||||||||||||||
| 569 | - | |||||||||||||||||||
| 570 | - | |||||||||||||||||||
| 571 | void QHttpNetworkConnectionChannel::setProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||||||||
| 572 | { | - | ||||||||||||||||||
| 573 | if (socket) | - | ||||||||||||||||||
| 574 | socket->setProxy(networkProxy); | - | ||||||||||||||||||
| 575 | - | |||||||||||||||||||
| 576 | proxy = networkProxy; | - | ||||||||||||||||||
| 577 | } | - | ||||||||||||||||||
| 578 | - | |||||||||||||||||||
| 579 | - | |||||||||||||||||||
| 580 | - | |||||||||||||||||||
| 581 | - | |||||||||||||||||||
| 582 | - | |||||||||||||||||||
| 583 | void QHttpNetworkConnectionChannel::ignoreSslErrors() | - | ||||||||||||||||||
| 584 | { | - | ||||||||||||||||||
| 585 | if (socket) | - | ||||||||||||||||||
| 586 | static_cast<QSslSocket *>(socket)->ignoreSslErrors(); | - | ||||||||||||||||||
| 587 | - | |||||||||||||||||||
| 588 | ignoreAllSslErrors = true; | - | ||||||||||||||||||
| 589 | } | - | ||||||||||||||||||
| 590 | - | |||||||||||||||||||
| 591 | - | |||||||||||||||||||
| 592 | void QHttpNetworkConnectionChannel::ignoreSslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
| 593 | { | - | ||||||||||||||||||
| 594 | if (socket) | - | ||||||||||||||||||
| 595 | static_cast<QSslSocket *>(socket)->ignoreSslErrors(errors); | - | ||||||||||||||||||
| 596 | - | |||||||||||||||||||
| 597 | ignoreSslErrorsList = errors; | - | ||||||||||||||||||
| 598 | } | - | ||||||||||||||||||
| 599 | - | |||||||||||||||||||
| 600 | void QHttpNetworkConnectionChannel::setSslConfiguration(const QSslConfiguration &config) | - | ||||||||||||||||||
| 601 | { | - | ||||||||||||||||||
| 602 | if (socket) | - | ||||||||||||||||||
| 603 | static_cast<QSslSocket *>(socket)->setSslConfiguration(config); | - | ||||||||||||||||||
| 604 | - | |||||||||||||||||||
| 605 | sslConfiguration = config; | - | ||||||||||||||||||
| 606 | } | - | ||||||||||||||||||
| 607 | - | |||||||||||||||||||
| 608 | - | |||||||||||||||||||
| 609 | - | |||||||||||||||||||
| 610 | void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) | - | ||||||||||||||||||
| 611 | { | - | ||||||||||||||||||
| 612 | - | |||||||||||||||||||
| 613 | - | |||||||||||||||||||
| 614 | QHttpNetworkRequest &request = pair.first; | - | ||||||||||||||||||
| 615 | QHttpNetworkReply *reply = pair.second; | - | ||||||||||||||||||
| 616 | reply->d_func()->clear(); | - | ||||||||||||||||||
| 617 | reply->d_func()->connection = connection; | - | ||||||||||||||||||
| 618 | reply->d_func()->connectionChannel = this; | - | ||||||||||||||||||
| 619 | reply->d_func()->autoDecompress = request.d->autoDecompress; | - | ||||||||||||||||||
| 620 | reply->d_func()->pipeliningUsed = true; | - | ||||||||||||||||||
| 621 | - | |||||||||||||||||||
| 622 | - | |||||||||||||||||||
| 623 | pipeline.append(QHttpNetworkRequestPrivate::header(request, | - | ||||||||||||||||||
| 624 | (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy))); | - | ||||||||||||||||||
| 625 | - | |||||||||||||||||||
| 626 | - | |||||||||||||||||||
| 627 | - | |||||||||||||||||||
| 628 | - | |||||||||||||||||||
| 629 | alreadyPipelinedRequests.append(pair); | - | ||||||||||||||||||
| 630 | - | |||||||||||||||||||
| 631 | - | |||||||||||||||||||
| 632 | } | - | ||||||||||||||||||
| 633 | - | |||||||||||||||||||
| 634 | void QHttpNetworkConnectionChannel::pipelineFlush() | - | ||||||||||||||||||
| 635 | { | - | ||||||||||||||||||
| 636 | if (pipeline.isEmpty()) | - | ||||||||||||||||||
| 637 | return; | - | ||||||||||||||||||
| 638 | - | |||||||||||||||||||
| 639 | - | |||||||||||||||||||
| 640 | - | |||||||||||||||||||
| 641 | - | |||||||||||||||||||
| 642 | - | |||||||||||||||||||
| 643 | - | |||||||||||||||||||
| 644 | socket->write(pipeline); | - | ||||||||||||||||||
| 645 | pipeline.clear(); | - | ||||||||||||||||||
| 646 | } | - | ||||||||||||||||||
| 647 | - | |||||||||||||||||||
| 648 | - | |||||||||||||||||||
| 649 | void QHttpNetworkConnectionChannel::closeAndResendCurrentRequest() | - | ||||||||||||||||||
| 650 | { | - | ||||||||||||||||||
| 651 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 652 | close(); | - | ||||||||||||||||||
| 653 | if (reply) | - | ||||||||||||||||||
| 654 | resendCurrent = true; | - | ||||||||||||||||||
| 655 | if (qobject_cast<QHttpNetworkConnection*>(connection)) | - | ||||||||||||||||||
| 656 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 657 | } | - | ||||||||||||||||||
| 658 | - | |||||||||||||||||||
| 659 | void QHttpNetworkConnectionChannel::resendCurrentRequest() | - | ||||||||||||||||||
| 660 | { | - | ||||||||||||||||||
| 661 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 662 | if (reply) | - | ||||||||||||||||||
| 663 | resendCurrent = true; | - | ||||||||||||||||||
| 664 | if (qobject_cast<QHttpNetworkConnection*>(connection)) | - | ||||||||||||||||||
| 665 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 666 | } | - | ||||||||||||||||||
| 667 | - | |||||||||||||||||||
| 668 | bool QHttpNetworkConnectionChannel::isSocketBusy() const | - | ||||||||||||||||||
| 669 | { | - | ||||||||||||||||||
| 670 | return (state & QHttpNetworkConnectionChannel::BusyState); | - | ||||||||||||||||||
| 671 | } | - | ||||||||||||||||||
| 672 | - | |||||||||||||||||||
| 673 | bool QHttpNetworkConnectionChannel::isSocketWriting() const | - | ||||||||||||||||||
| 674 | { | - | ||||||||||||||||||
| 675 | return (state & QHttpNetworkConnectionChannel::WritingState); | - | ||||||||||||||||||
| 676 | } | - | ||||||||||||||||||
| 677 | - | |||||||||||||||||||
| 678 | bool QHttpNetworkConnectionChannel::isSocketWaiting() const | - | ||||||||||||||||||
| 679 | { | - | ||||||||||||||||||
| 680 | return (state & QHttpNetworkConnectionChannel::WaitingState); | - | ||||||||||||||||||
| 681 | } | - | ||||||||||||||||||
| 682 | - | |||||||||||||||||||
| 683 | bool QHttpNetworkConnectionChannel::isSocketReading() const | - | ||||||||||||||||||
| 684 | { | - | ||||||||||||||||||
| 685 | return (state & QHttpNetworkConnectionChannel::ReadingState); | - | ||||||||||||||||||
| 686 | } | - | ||||||||||||||||||
| 687 | - | |||||||||||||||||||
| 688 | void QHttpNetworkConnectionChannel::_q_bytesWritten(qint64 bytes) | - | ||||||||||||||||||
| 689 | { | - | ||||||||||||||||||
| 690 | (void)bytes;; | - | ||||||||||||||||||
| 691 | if (ssl) { | - | ||||||||||||||||||
| 692 | - | |||||||||||||||||||
| 693 | - | |||||||||||||||||||
| 694 | return; | - | ||||||||||||||||||
| 695 | } | - | ||||||||||||||||||
| 696 | - | |||||||||||||||||||
| 697 | - | |||||||||||||||||||
| 698 | if (isSocketWriting()) | - | ||||||||||||||||||
| 699 | sendRequest(); | - | ||||||||||||||||||
| 700 | - | |||||||||||||||||||
| 701 | } | - | ||||||||||||||||||
| 702 | - | |||||||||||||||||||
| 703 | void QHttpNetworkConnectionChannel::_q_disconnected() | - | ||||||||||||||||||
| 704 | { | - | ||||||||||||||||||
| 705 | if (state == QHttpNetworkConnectionChannel::ClosingState) { | - | ||||||||||||||||||
| 706 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 707 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 708 | return; | - | ||||||||||||||||||
| 709 | } | - | ||||||||||||||||||
| 710 | - | |||||||||||||||||||
| 711 | - | |||||||||||||||||||
| 712 | if ((isSocketWaiting() || isSocketReading()) && socket->bytesAvailable()) { | - | ||||||||||||||||||
| 713 | if (reply) { | - | ||||||||||||||||||
| 714 | state = QHttpNetworkConnectionChannel::ReadingState; | - | ||||||||||||||||||
| 715 | _q_receiveReply(); | - | ||||||||||||||||||
| 716 | } | - | ||||||||||||||||||
| 717 | } else if (state == QHttpNetworkConnectionChannel::IdleState && resendCurrent) { | - | ||||||||||||||||||
| 718 | - | |||||||||||||||||||
| 719 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 720 | } | - | ||||||||||||||||||
| 721 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 722 | - | |||||||||||||||||||
| 723 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 724 | - | |||||||||||||||||||
| 725 | pendingEncrypt = false; | - | ||||||||||||||||||
| 726 | } | - | ||||||||||||||||||
| 727 | - | |||||||||||||||||||
| 728 | - | |||||||||||||||||||
| 729 | void QHttpNetworkConnectionChannel::_q_connected() | - | ||||||||||||||||||
| 730 | { | - | ||||||||||||||||||
| 731 | - | |||||||||||||||||||
| 732 | if (connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::HostLookupPending || connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4or6) { | - | ||||||||||||||||||
| 733 | if (connection->d_func()->delayedConnectionTimer.isActive()) | - | ||||||||||||||||||
| 734 | connection->d_func()->delayedConnectionTimer.stop(); | - | ||||||||||||||||||
| 735 | if (networkLayerPreference == QAbstractSocket::IPv4Protocol) | - | ||||||||||||||||||
| 736 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; | - | ||||||||||||||||||
| 737 | else if (networkLayerPreference == QAbstractSocket::IPv6Protocol) | - | ||||||||||||||||||
| 738 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | - | ||||||||||||||||||
| 739 | else { | - | ||||||||||||||||||
| 740 | if (socket->peerAddress().protocol() == QAbstractSocket::IPv4Protocol) | - | ||||||||||||||||||
| 741 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; | - | ||||||||||||||||||
| 742 | else | - | ||||||||||||||||||
| 743 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | - | ||||||||||||||||||
| 744 | } | - | ||||||||||||||||||
| 745 | connection->d_func()->networkLayerDetected(networkLayerPreference); | - | ||||||||||||||||||
| 746 | } else { | - | ||||||||||||||||||
| 747 | if (((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (networkLayerPreference != QAbstractSocket::IPv4Protocol)) | - | ||||||||||||||||||
| 748 | || ((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (networkLayerPreference != QAbstractSocket::IPv6Protocol))) { | - | ||||||||||||||||||
| 749 | close(); | - | ||||||||||||||||||
| 750 | - | |||||||||||||||||||
| 751 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 752 | return; | - | ||||||||||||||||||
| 753 | } | - | ||||||||||||||||||
| 754 | - | |||||||||||||||||||
| 755 | } | - | ||||||||||||||||||
| 756 | socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1); | - | ||||||||||||||||||
| 757 | - | |||||||||||||||||||
| 758 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown; | - | ||||||||||||||||||
| 759 | - | |||||||||||||||||||
| 760 | - | |||||||||||||||||||
| 761 | - | |||||||||||||||||||
| 762 | if (ssl || pendingEncrypt) { | - | ||||||||||||||||||
| 763 | - | |||||||||||||||||||
| 764 | if (connection->sslContext().isNull()) { | - | ||||||||||||||||||
| 765 | - | |||||||||||||||||||
| 766 | - | |||||||||||||||||||
| 767 | QSharedPointer<QSslContext> socketSslContext = QSslSocketPrivate::sslContext(static_cast<QSslSocket*>(socket)); | - | ||||||||||||||||||
| 768 | if (!socketSslContext.isNull()) | - | ||||||||||||||||||
| 769 | connection->setSslContext(socketSslContext); | - | ||||||||||||||||||
| 770 | } | - | ||||||||||||||||||
| 771 | - | |||||||||||||||||||
| 772 | } else { | - | ||||||||||||||||||
| 773 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 774 | if (!reply) | - | ||||||||||||||||||
| 775 | connection->d_func()->dequeueRequest(socket); | - | ||||||||||||||||||
| 776 | if (reply) | - | ||||||||||||||||||
| 777 | sendRequest(); | - | ||||||||||||||||||
| 778 | } | - | ||||||||||||||||||
| 779 | } | - | ||||||||||||||||||
| 780 | - | |||||||||||||||||||
| 781 | - | |||||||||||||||||||
| 782 | void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socketError) | - | ||||||||||||||||||
| 783 | { | - | ||||||||||||||||||
| 784 | if (!socket) | - | ||||||||||||||||||
| 785 | return; | - | ||||||||||||||||||
| 786 | QNetworkReply::NetworkError errorCode = QNetworkReply::UnknownNetworkError; | - | ||||||||||||||||||
| 787 | - | |||||||||||||||||||
| 788 | switch (socketError) { | - | ||||||||||||||||||
| 789 | case QAbstractSocket::HostNotFoundError: | - | ||||||||||||||||||
| 790 | errorCode = QNetworkReply::HostNotFoundError; | - | ||||||||||||||||||
| 791 | break; | - | ||||||||||||||||||
| 792 | case QAbstractSocket::ConnectionRefusedError: | - | ||||||||||||||||||
| 793 | errorCode = QNetworkReply::ConnectionRefusedError; | - | ||||||||||||||||||
| 794 | break; | - | ||||||||||||||||||
| 795 | case QAbstractSocket::RemoteHostClosedError: | - | ||||||||||||||||||
| 796 | - | |||||||||||||||||||
| 797 | - | |||||||||||||||||||
| 798 | - | |||||||||||||||||||
| 799 | if (!reply && state == QHttpNetworkConnectionChannel::IdleState) { | - | ||||||||||||||||||
| 800 | - | |||||||||||||||||||
| 801 | - | |||||||||||||||||||
| 802 | - | |||||||||||||||||||
| 803 | return; | - | ||||||||||||||||||
| 804 | } else if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) { | - | ||||||||||||||||||
| 805 | - | |||||||||||||||||||
| 806 | - | |||||||||||||||||||
| 807 | if (reconnectAttempts-- > 0) { | - | ||||||||||||||||||
| 808 | resendCurrentRequest(); | - | ||||||||||||||||||
| 809 | return; | - | ||||||||||||||||||
| 810 | } else { | - | ||||||||||||||||||
| 811 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
| 812 | } | - | ||||||||||||||||||
| 813 | } else if (state == QHttpNetworkConnectionChannel::ReadingState) { | - | ||||||||||||||||||
| 814 | if (!reply) | - | ||||||||||||||||||
| 815 | break; | - | ||||||||||||||||||
| 816 | - | |||||||||||||||||||
| 817 | if (!reply->d_func()->expectContent()) { | - | ||||||||||||||||||
| 818 | - | |||||||||||||||||||
| 819 | - | |||||||||||||||||||
| 820 | QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection); | - | ||||||||||||||||||
| 821 | return; | - | ||||||||||||||||||
| 822 | } | - | ||||||||||||||||||
| 823 | if (reply->contentLength() == -1 && !reply->d_func()->isChunked()) { | - | ||||||||||||||||||
| 824 | - | |||||||||||||||||||
| 825 | - | |||||||||||||||||||
| 826 | - | |||||||||||||||||||
| 827 | QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection); | - | ||||||||||||||||||
| 828 | return; | - | ||||||||||||||||||
| 829 | } | - | ||||||||||||||||||
| 830 | - | |||||||||||||||||||
| 831 | - | |||||||||||||||||||
| 832 | if (socket->bytesAvailable()) { | - | ||||||||||||||||||
| 833 | - | |||||||||||||||||||
| 834 | - | |||||||||||||||||||
| 835 | - | |||||||||||||||||||
| 836 | reply->setReadBufferSize(0); | - | ||||||||||||||||||
| 837 | reply->setDownstreamLimited(false); | - | ||||||||||||||||||
| 838 | _q_receiveReply(); | - | ||||||||||||||||||
| 839 | if (!reply) { | - | ||||||||||||||||||
| 840 | - | |||||||||||||||||||
| 841 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
| 842 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 843 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 844 | return; | - | ||||||||||||||||||
| 845 | } | - | ||||||||||||||||||
| 846 | } | - | ||||||||||||||||||
| 847 | - | |||||||||||||||||||
| 848 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
| 849 | } else { | - | ||||||||||||||||||
| 850 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
| 851 | } | - | ||||||||||||||||||
| 852 | break; | - | ||||||||||||||||||
| 853 | case QAbstractSocket::SocketTimeoutError: | - | ||||||||||||||||||
| 854 | - | |||||||||||||||||||
| 855 | if (state == QHttpNetworkConnectionChannel::WritingState && (reconnectAttempts-- > 0)) { | - | ||||||||||||||||||
| 856 | resendCurrentRequest(); | - | ||||||||||||||||||
| 857 | return; | - | ||||||||||||||||||
| 858 | } | - | ||||||||||||||||||
| 859 | errorCode = QNetworkReply::TimeoutError; | - | ||||||||||||||||||
| 860 | break; | - | ||||||||||||||||||
| 861 | case QAbstractSocket::ProxyAuthenticationRequiredError: | - | ||||||||||||||||||
| 862 | errorCode = QNetworkReply::ProxyAuthenticationRequiredError; | - | ||||||||||||||||||
| 863 | break; | - | ||||||||||||||||||
| 864 | case QAbstractSocket::SslHandshakeFailedError: | - | ||||||||||||||||||
| 865 | errorCode = QNetworkReply::SslHandshakeFailedError; | - | ||||||||||||||||||
| 866 | break; | - | ||||||||||||||||||
| 867 | case QAbstractSocket::ProxyConnectionClosedError: | - | ||||||||||||||||||
| 868 | - | |||||||||||||||||||
| 869 | if (reconnectAttempts-- > 0) { | - | ||||||||||||||||||
| 870 | resendCurrentRequest(); | - | ||||||||||||||||||
| 871 | return; | - | ||||||||||||||||||
| 872 | } | - | ||||||||||||||||||
| 873 | errorCode = QNetworkReply::ProxyConnectionClosedError; | - | ||||||||||||||||||
| 874 | break; | - | ||||||||||||||||||
| 875 | case QAbstractSocket::ProxyConnectionTimeoutError: | - | ||||||||||||||||||
| 876 | - | |||||||||||||||||||
| 877 | if (reconnectAttempts-- > 0) { | - | ||||||||||||||||||
| 878 | resendCurrentRequest(); | - | ||||||||||||||||||
| 879 | return; | - | ||||||||||||||||||
| 880 | } | - | ||||||||||||||||||
| 881 | errorCode = QNetworkReply::ProxyTimeoutError; | - | ||||||||||||||||||
| 882 | break; | - | ||||||||||||||||||
| 883 | default: | - | ||||||||||||||||||
| 884 | - | |||||||||||||||||||
| 885 | errorCode = QNetworkReply::UnknownNetworkError; | - | ||||||||||||||||||
| 886 | break; | - | ||||||||||||||||||
| 887 | } | - | ||||||||||||||||||
| 888 | QPointer<QHttpNetworkConnection> that = connection; | - | ||||||||||||||||||
| 889 | QString errorString = connection->d_func()->errorDetail(errorCode, socket, socket->errorString()); | - | ||||||||||||||||||
| 890 | - | |||||||||||||||||||
| 891 | - | |||||||||||||||||||
| 892 | - | |||||||||||||||||||
| 893 | if (!connection->d_func()->shouldEmitChannelError(socket)) | - | ||||||||||||||||||
| 894 | return; | - | ||||||||||||||||||
| 895 | - | |||||||||||||||||||
| 896 | - | |||||||||||||||||||
| 897 | do { | - | ||||||||||||||||||
| 898 | - | |||||||||||||||||||
| 899 | if (!reply) | - | ||||||||||||||||||
| 900 | connection->d_func()->dequeueRequest(socket); | - | ||||||||||||||||||
| 901 | - | |||||||||||||||||||
| 902 | if (reply) { | - | ||||||||||||||||||
| 903 | reply->d_func()->errorString = errorString; | - | ||||||||||||||||||
| 904 | reply->finishedWithError(errorCode, errorString); | - | ||||||||||||||||||
| 905 | reply = 0; | - | ||||||||||||||||||
| 906 | if (protocolHandler) | - | ||||||||||||||||||
| 907 | protocolHandler->setReply(0); | - | ||||||||||||||||||
| 908 | } | - | ||||||||||||||||||
| 909 | } while (!connection->d_func()->highPriorityQueue.isEmpty() | - | ||||||||||||||||||
| 910 | || !connection->d_func()->lowPriorityQueue.isEmpty()); | - | ||||||||||||||||||
| 911 | - | |||||||||||||||||||
| 912 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) { | - | ||||||||||||||||||
| 913 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 914 | for (int a = 0; a < spdyPairs.count(); ++a) { | - | ||||||||||||||||||
| 915 | - | |||||||||||||||||||
| 916 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
| 917 | ((!(currentReply)) ? qt_assert("currentReply",__FILE__,973979) : qt_noop()); | - | ||||||||||||||||||
| 918 | currentReply->finishedWithError(errorCode, errorString); | - | ||||||||||||||||||
| 919 | } | - | ||||||||||||||||||
| 920 | } | - | ||||||||||||||||||
| 921 | - | |||||||||||||||||||
| 922 | - | |||||||||||||||||||
| 923 | - | |||||||||||||||||||
| 924 | QMetaObject::invokeMethod(that, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 925 | - | |||||||||||||||||||
| 926 | if (that) { | - | ||||||||||||||||||
| 927 | - | |||||||||||||||||||
| 928 | if (!socket) | - | ||||||||||||||||||
| 929 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 930 | else if (socket->state() == QAbstractSocket::UnconnectedState) | - | ||||||||||||||||||
| 931 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 932 | else | - | ||||||||||||||||||
| 933 | state = QHttpNetworkConnectionChannel::ClosingState; | - | ||||||||||||||||||
| 934 | - | |||||||||||||||||||
| 935 | - | |||||||||||||||||||
| 936 | pendingEncrypt = false; | - | ||||||||||||||||||
| 937 | } | - | ||||||||||||||||||
| 938 | } | - | ||||||||||||||||||
| 939 | - | |||||||||||||||||||
| 940 | - | |||||||||||||||||||
| 941 | void QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator* auth) | - | ||||||||||||||||||
| 942 | { | - | ||||||||||||||||||
| 943 | - | |||||||||||||||||||
| 944 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) { | - | ||||||||||||||||||
| 945 | connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth); | - | ||||||||||||||||||
| 946 | } else { | - | ||||||||||||||||||
| 947 | - | |||||||||||||||||||
| 948 | - | |||||||||||||||||||
| 949 | if (!reply) | - | ||||||||||||||||||
| 950 | connection->d_func()->dequeueRequest(socket); | - | ||||||||||||||||||
| 951 | if (reply) | - | ||||||||||||||||||
| 952 | connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth); | - | ||||||||||||||||||
| 953 | - | |||||||||||||||||||
| 954 | } | - | ||||||||||||||||||
| 955 | - | |||||||||||||||||||
| 956 | } | - | ||||||||||||||||||
| 957 | - | |||||||||||||||||||
| 958 | - | |||||||||||||||||||
| 959 | void QHttpNetworkConnectionChannel::_q_uploadDataReadyRead() | - | ||||||||||||||||||
| 960 | { | - | ||||||||||||||||||
| 961 | if (reply) | - | ||||||||||||||||||
| 962 | sendRequest(); | - | ||||||||||||||||||
| 963 | } | - | ||||||||||||||||||
| 964 | - | |||||||||||||||||||
| 965 | - | |||||||||||||||||||
| 966 | void QHttpNetworkConnectionChannel::_q_encrypted() | - | ||||||||||||||||||
| 967 | { | - | ||||||||||||||||||
| 968 | QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket); | - | ||||||||||||||||||
| 969 | ((!(sslSocket)) ? qt_assert("sslSocket",__FILE__,10251031) : qt_noop()); | - | ||||||||||||||||||
| 970 | - | |||||||||||||||||||
| 971 | if (!protocolHandler) { | - | ||||||||||||||||||
| 972 | switch (sslSocket->sslConfiguration().nextProtocolNegotiationStatus()) { | - | ||||||||||||||||||
| 973 | case QSslConfiguration::NextProtocolNegotiationNegotiated: | - | ||||||||||||||||||
| 974 | case QSslConfiguration::NextProtocolNegotiationUnsupported: { | - | ||||||||||||||||||
| 975 | QByteArray nextProtocol = sslSocket->sslConfiguration().nextNegotiatedProtocol(); | - | ||||||||||||||||||
| 976 | if (nextProtocol == QSslConfiguration::NextProtocolHttp1_1) { | - | ||||||||||||||||||
| 977 | - | |||||||||||||||||||
| 978 | } else if (nextProtocol == QSslConfiguration::NextProtocolSpdy3_0) { | - | ||||||||||||||||||
| 979 | protocolHandler.reset(new QSpdyProtocolHandler(this)); | - | ||||||||||||||||||
| 980 | connection->setConnectionType(QHttpNetworkConnection::ConnectionTypeSPDY); | - | ||||||||||||||||||
| 981 | - | |||||||||||||||||||
| 982 | - | |||||||||||||||||||
| 983 | break; | - | ||||||||||||||||||
| 984 | } else { | - | ||||||||||||||||||
| 985 | emitFinishedWithError(QNetworkReply::SslHandshakeFailedError, | - | ||||||||||||||||||
| 986 | "detected unknown Next Protocol Negotiation protocol"); | - | ||||||||||||||||||
| 987 | break; | - | ||||||||||||||||||
| 988 | } | - | ||||||||||||||||||
| 989 | } | - | ||||||||||||||||||
| 990 | case QSslConfiguration::NextProtocolNegotiationNone: | - | ||||||||||||||||||
| 991 | protocolHandler.reset(new QHttpProtocolHandler(this)); | - | ||||||||||||||||||
| 992 | connection->setConnectionType(QHttpNetworkConnection::ConnectionTypeHTTP); | - | ||||||||||||||||||
| 993 | - | |||||||||||||||||||
| 994 | requeueSpdyRequests(); | - | ||||||||||||||||||
| 995 | break; | - | ||||||||||||||||||
| 996 | default: | - | ||||||||||||||||||
| 997 | emitFinishedWithError(QNetworkReply::SslHandshakeFailedError, | - | ||||||||||||||||||
| 998 | "detected unknown Next Protocol Negotiation protocol"); | - | ||||||||||||||||||
| 999 | } | - | ||||||||||||||||||
| 1000 | } | - | ||||||||||||||||||
| 1001 | - | |||||||||||||||||||
| 1002 | if (!socket) | - | ||||||||||||||||||
| 1003 | return; | - | ||||||||||||||||||
| 1004 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
| 1005 | pendingEncrypt = false; | - | ||||||||||||||||||
| 1006 | - | |||||||||||||||||||
| 1007 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) { | - | ||||||||||||||||||
| 1008 | - | |||||||||||||||||||
| 1009 | if (spdyRequestsToSend.count() > 0) | - | ||||||||||||||||||
| 1010 | - | |||||||||||||||||||
| 1011 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
| 1012 | } else { | - | ||||||||||||||||||
| 1013 | if (!reply) | - | ||||||||||||||||||
| 1014 | connection->d_func()->dequeueRequest(socket); | - | ||||||||||||||||||
| 1015 | if (reply) { | - | ||||||||||||||||||
| 1016 | reply->setSpdyWasUsed(false); | - | ||||||||||||||||||
| 1017 | ((!(reply->d_func()->connectionChannel == this)) ? qt_assert("reply->d_func()->connectionChannel == this",__FILE__,10731079) : qt_noop()); | - | ||||||||||||||||||
| 1018 | reply->encrypted(); | - | ||||||||||||||||||
| 1019 | } | - | ||||||||||||||||||
| 1020 | if (reply) | - | ||||||||||||||||||
| 1021 | sendRequest(); | - | ||||||||||||||||||
| 1022 | } | - | ||||||||||||||||||
| 1023 | } | - | ||||||||||||||||||
| 1024 | - | |||||||||||||||||||
| 1025 | void QHttpNetworkConnectionChannel::requeueSpdyRequests() | - | ||||||||||||||||||
| 1026 | { | - | ||||||||||||||||||
| 1027 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 1028 | for (int a = 0; a < spdyPairs.count(); ++a) { | - | ||||||||||||||||||
| 1029 | connection->d_func()->requeueRequest(spdyPairs.at(a)); | - | ||||||||||||||||||
| 1030 | } | - | ||||||||||||||||||
| 1031 | spdyRequestsToSend.clear(); | - | ||||||||||||||||||
| 1032 | } | - | ||||||||||||||||||
| 1033 | - | |||||||||||||||||||
| 1034 | void QHttpNetworkConnectionChannel::emitFinishedWithError(QNetworkReply::NetworkError error, | - | ||||||||||||||||||
| 1035 | const char *message) | - | ||||||||||||||||||
| 1036 | { | - | ||||||||||||||||||
| 1037 | if (reply) | - | ||||||||||||||||||
| 1038 | reply->finishedWithError(error, QHttpNetworkConnectionChannel::tr(message)); | - | ||||||||||||||||||
| 1039 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 1040 | for (int a = 0; a < spdyPairs.count(); ++a) { | - | ||||||||||||||||||
| 1041 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
| 1042 | ((!(currentReply)) ? qt_assert("currentReply",__FILE__,10981104) : qt_noop()); | - | ||||||||||||||||||
| 1043 | currentReply->finishedWithError(error, QHttpNetworkConnectionChannel::tr(message)); | - | ||||||||||||||||||
| 1044 | } | - | ||||||||||||||||||
| 1045 | } | - | ||||||||||||||||||
| 1046 | - | |||||||||||||||||||
| 1047 | void QHttpNetworkConnectionChannel::_q_sslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
| 1048 | { | - | ||||||||||||||||||
| 1049 | if (!socket) | - | ||||||||||||||||||
| 1050 | return; | - | ||||||||||||||||||
| 1051 | - | |||||||||||||||||||
| 1052 | - | |||||||||||||||||||
| 1053 | - | |||||||||||||||||||
| 1054 | connection->d_func()->pauseConnection(); | - | ||||||||||||||||||
| 1055 | if (pendingEncrypt && !reply) | - | ||||||||||||||||||
| 1056 | connection->d_func()->dequeueRequest(socket); | - | ||||||||||||||||||
| 1057 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP) { | - | ||||||||||||||||||
| 1058 | if (reply) | - | ||||||||||||||||||
| 1059 | reply->sslErrors(errors); | - | ||||||||||||||||||
| 1060 | } | - | ||||||||||||||||||
| 1061 | - | |||||||||||||||||||
| 1062 | else { | - | ||||||||||||||||||
| 1063 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 1064 | for (int a = 0; a < spdyPairs.count(); ++a) { | - | ||||||||||||||||||
| 1065 | - | |||||||||||||||||||
| 1066 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
| 1067 | ((!(currentReply)) ? qt_assert("currentReply",__FILE__,11231129) : qt_noop()); | - | ||||||||||||||||||
| 1068 | currentReply->sslErrors(errors); | - | ||||||||||||||||||
| 1069 | } | - | ||||||||||||||||||
| 1070 | } | - | ||||||||||||||||||
| 1071 | - | |||||||||||||||||||
| 1072 | connection->d_func()->resumeConnection(); | - | ||||||||||||||||||
| 1073 | } | - | ||||||||||||||||||
| 1074 | - | |||||||||||||||||||
| 1075 | void QHttpNetworkConnectionChannel::_q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator) | - | ||||||||||||||||||
| 1076 | { | - | ||||||||||||||||||
| 1077 | connection->d_func()->pauseConnection(); | - | ||||||||||||||||||
| 1078 | - | |||||||||||||||||||
| 1079 | if (pendingEncrypt && !reply) | - | ||||||||||||||||||
| 1080 | connection->d_func()->dequeueRequest(socket); | - | ||||||||||||||||||
| 1081 | - | |||||||||||||||||||
| 1082 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP) { | - | ||||||||||||||||||
| 1083 | if (reply) | - | ||||||||||||||||||
| 1084 | reply->preSharedKeyAuthenticationRequired(authenticator); | - | ||||||||||||||||||
| 1085 | } else { | - | ||||||||||||||||||
| 1086 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
| 1087 | for (int a = 0; a < spdyPairs.count(); ++a) { | - | ||||||||||||||||||
| 1088 | - | |||||||||||||||||||
| 1089 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
| 1090 | ((!(currentReply)) ? qt_assert("currentReply",__FILE__,11461152) : qt_noop()); | - | ||||||||||||||||||
| 1091 | currentReply->preSharedKeyAuthenticationRequired(authenticator); | - | ||||||||||||||||||
| 1092 | } | - | ||||||||||||||||||
| 1093 | } | - | ||||||||||||||||||
| 1094 | - | |||||||||||||||||||
| 1095 | connection->d_func()->resumeConnection(); | - | ||||||||||||||||||
| 1096 | } | - | ||||||||||||||||||
| 1097 | - | |||||||||||||||||||
| 1098 | void QHttpNetworkConnectionChannel::_q_encryptedBytesWritten(qint64 bytes) | - | ||||||||||||||||||
| 1099 | { | - | ||||||||||||||||||
| 1100 | (void)bytes;; | - | ||||||||||||||||||
| 1101 | - | |||||||||||||||||||
| 1102 | if (isSocketWriting()) | - | ||||||||||||||||||
| 1103 | sendRequest(); | - | ||||||||||||||||||
| 1104 | - | |||||||||||||||||||
| 1105 | } | - | ||||||||||||||||||
| 1106 | - | |||||||||||||||||||
| 1107 | - | |||||||||||||||||||
| 1108 | - | |||||||||||||||||||
| 1109 | void QHttpNetworkConnectionChannel::setConnection(QHttpNetworkConnection *c) | - | ||||||||||||||||||
| 1110 | { | - | ||||||||||||||||||
| 1111 | - | |||||||||||||||||||
| 1112 | - | |||||||||||||||||||
| 1113 | connection = c; | - | ||||||||||||||||||
| 1114 | } | - | ||||||||||||||||||
| 1115 | - | |||||||||||||||||||
| 1116 | - | |||||||||||||||||||
| 1117 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |