src/network/access/qhttpnetworkconnectionchannel.cpp
changeset 30 5dc02b23752f
parent 25 e24348a560a6
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   171         reply->d_func()->pipeliningUsed = false;
   171         reply->d_func()->pipeliningUsed = false;
   172 
   172 
   173         pendingEncrypt = false;
   173         pendingEncrypt = false;
   174         // if the url contains authentication parameters, use the new ones
   174         // if the url contains authentication parameters, use the new ones
   175         // both channels will use the new authentication parameters
   175         // both channels will use the new authentication parameters
   176         if (!request.url().userInfo().isEmpty()) {
   176         if (!request.url().userInfo().isEmpty() && request.withCredentials()) {
   177             QUrl url = request.url();
   177             QUrl url = request.url();
   178             QAuthenticator &auth = authenticator;
   178             QAuthenticator &auth = authenticator;
   179             if (url.userName() != auth.user()
   179             if (url.userName() != auth.user()
   180                 || (!url.password().isEmpty() && url.password() != auth.password())) {
   180                 || (!url.password().isEmpty() && url.password() != auth.password())) {
   181                 auth.setUser(url.userName());
   181                 auth.setUser(url.userName());
   185             // clear the userinfo,  since we use the same request for resending
   185             // clear the userinfo,  since we use the same request for resending
   186             // userinfo in url can conflict with the one in the authenticator
   186             // userinfo in url can conflict with the one in the authenticator
   187             url.setUserInfo(QString());
   187             url.setUserInfo(QString());
   188             request.setUrl(url);
   188             request.setUrl(url);
   189         }
   189         }
   190         connection->d_func()->createAuthorization(socket, request);
   190         // Will only be false if QtWebKit is performing a cross-origin XMLHttpRequest
       
   191         // and withCredentials has not been set to true.
       
   192         if (request.withCredentials())
       
   193             connection->d_func()->createAuthorization(socket, request);
   191 #ifndef QT_NO_NETWORKPROXY
   194 #ifndef QT_NO_NETWORKPROXY
   192         QByteArray header = QHttpNetworkRequestPrivate::header(request,
   195         QByteArray header = QHttpNetworkRequestPrivate::header(request,
   193             (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy));
   196             (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy));
   194 #else
   197 #else
   195         QByteArray header = QHttpNetworkRequestPrivate::header(request, false);
   198         QByteArray header = QHttpNetworkRequestPrivate::header(request, false);
   283         if (uploadByteDevice) {
   286         if (uploadByteDevice) {
   284             QObject::disconnect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(_q_uploadDataReadyRead()));
   287             QObject::disconnect(uploadByteDevice, SIGNAL(readyRead()), this, SLOT(_q_uploadDataReadyRead()));
   285         }
   288         }
   286 
   289 
   287         // HTTP pipelining
   290         // HTTP pipelining
   288         connection->d_func()->fillPipeline(socket);
   291         //connection->d_func()->fillPipeline(socket);
   289         socket->flush();
   292         //socket->flush();
   290 
   293 
   291         // ensure we try to receive a reply in all cases, even if _q_readyRead_ hat not been called
   294         // ensure we try to receive a reply in all cases, even if _q_readyRead_ hat not been called
   292         // this is needed if the sends an reply before we have finished sending the request. In that
   295         // this is needed if the sends an reply before we have finished sending the request. In that
   293         // case receiveReply had been called before but ignored the server reply
   296         // case receiveReply had been called before but ignored the server reply
   294         if (socket->bytesAvailable())
   297         if (socket->bytesAvailable())
   677         // this is weird. we had nothing pipelined but still bytes available. better close it.
   680         // this is weird. we had nothing pipelined but still bytes available. better close it.
   678         if (socket->bytesAvailable() > 0)
   681         if (socket->bytesAvailable() > 0)
   679             close();
   682             close();
   680         QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
   683         QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
   681     } else if (alreadyPipelinedRequests.isEmpty()) {
   684     } else if (alreadyPipelinedRequests.isEmpty()) {
   682         QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
   685         if (qobject_cast<QHttpNetworkConnection*>(connection))
       
   686             QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
   683     }
   687     }
   684 }
   688 }
   685 
   689 
   686 void QHttpNetworkConnectionChannel::detectPipeliningSupport()
   690 void QHttpNetworkConnectionChannel::detectPipeliningSupport()
   687 {
   691 {
   784             emit connection->error(errorCode, reply->d_func()->errorString);
   788             emit connection->error(errorCode, reply->d_func()->errorString);
   785             emit reply->finished();
   789             emit reply->finished();
   786         }
   790         }
   787         break;
   791         break;
   788     default:
   792     default:
   789         QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
   793         if (qobject_cast<QHttpNetworkConnection*>(connection))
       
   794             QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
   790     }
   795     }
   791 }
   796 }
   792 
   797 
   793 bool QHttpNetworkConnectionChannel::resetUploadData()
   798 bool QHttpNetworkConnectionChannel::resetUploadData()
   794 {
   799 {
   832 void QHttpNetworkConnectionChannel::closeAndResendCurrentRequest()
   837 void QHttpNetworkConnectionChannel::closeAndResendCurrentRequest()
   833 {
   838 {
   834     requeueCurrentlyPipelinedRequests();
   839     requeueCurrentlyPipelinedRequests();
   835     close();
   840     close();
   836     resendCurrent = true;
   841     resendCurrent = true;
   837     QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
   842     if (qobject_cast<QHttpNetworkConnection*>(connection))
       
   843         QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection);
   838 }
   844 }
   839 
   845 
   840 bool QHttpNetworkConnectionChannel::isSocketBusy() const
   846 bool QHttpNetworkConnectionChannel::isSocketBusy() const
   841 {
   847 {
   842     return (state & QHttpNetworkConnectionChannel::BusyState);
   848     return (state & QHttpNetworkConnectionChannel::BusyState);