402 |
402 |
403 // The reply component of the pair is created initially. |
403 // The reply component of the pair is created initially. |
404 QHttpNetworkReply *reply = new QHttpNetworkReply(request.url()); |
404 QHttpNetworkReply *reply = new QHttpNetworkReply(request.url()); |
405 reply->setRequest(request); |
405 reply->setRequest(request); |
406 reply->d_func()->connection = q; |
406 reply->d_func()->connection = q; |
|
407 reply->d_func()->connectionChannel = &channels[0]; // will have the correct one set later |
407 HttpMessagePair pair = qMakePair(request, reply); |
408 HttpMessagePair pair = qMakePair(request, reply); |
408 |
409 |
409 switch (request.priority()) { |
410 switch (request.priority()) { |
410 case QHttpNetworkRequest::HighPriority: |
411 case QHttpNetworkRequest::HighPriority: |
411 highPriorityQueue.prepend(pair); |
412 highPriorityQueue.prepend(pair); |
413 case QHttpNetworkRequest::NormalPriority: |
414 case QHttpNetworkRequest::NormalPriority: |
414 case QHttpNetworkRequest::LowPriority: |
415 case QHttpNetworkRequest::LowPriority: |
415 lowPriorityQueue.prepend(pair); |
416 lowPriorityQueue.prepend(pair); |
416 break; |
417 break; |
417 } |
418 } |
|
419 |
418 // this used to be called via invokeMethod and a QueuedConnection |
420 // this used to be called via invokeMethod and a QueuedConnection |
|
421 // It is the only place _q_startNextRequest is called directly without going |
|
422 // through the event loop using a QueuedConnection. |
|
423 // This is dangerous because of recursion that might occur when emitting |
|
424 // signals as DirectConnection from this code path. Therefore all signal |
|
425 // emissions that can come out from this code path need to |
|
426 // be QueuedConnection. |
|
427 // We are currently trying to fine-tune this. |
419 _q_startNextRequest(); |
428 _q_startNextRequest(); |
|
429 |
|
430 |
420 return reply; |
431 return reply; |
421 } |
432 } |
422 |
433 |
423 void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair) |
434 void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair) |
424 { |
435 { |
|
436 Q_Q(QHttpNetworkConnection); |
|
437 |
425 QHttpNetworkRequest request = pair.first; |
438 QHttpNetworkRequest request = pair.first; |
426 switch (request.priority()) { |
439 switch (request.priority()) { |
427 case QHttpNetworkRequest::HighPriority: |
440 case QHttpNetworkRequest::HighPriority: |
428 highPriorityQueue.prepend(pair); |
441 highPriorityQueue.prepend(pair); |
429 break; |
442 break; |
430 case QHttpNetworkRequest::NormalPriority: |
443 case QHttpNetworkRequest::NormalPriority: |
431 case QHttpNetworkRequest::LowPriority: |
444 case QHttpNetworkRequest::LowPriority: |
432 lowPriorityQueue.prepend(pair); |
445 lowPriorityQueue.prepend(pair); |
433 break; |
446 break; |
434 } |
447 } |
435 // this used to be called via invokeMethod and a QueuedConnection |
448 |
436 _q_startNextRequest(); |
449 QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); |
437 } |
450 } |
438 |
451 |
439 void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socket) |
452 void QHttpNetworkConnectionPrivate::dequeueAndSendRequest(QAbstractSocket *socket) |
440 { |
453 { |
441 Q_ASSERT(socket); |
454 Q_ASSERT(socket); |
679 } |
692 } |
680 } |
693 } |
681 |
694 |
682 |
695 |
683 |
696 |
|
697 // This function must be called from the event loop. The only |
|
698 // exception is documented in QHttpNetworkConnectionPrivate::queueRequest |
684 void QHttpNetworkConnectionPrivate::_q_startNextRequest() |
699 void QHttpNetworkConnectionPrivate::_q_startNextRequest() |
685 { |
700 { |
686 //resend the necessary ones. |
701 //resend the necessary ones. |
687 for (int i = 0; i < channelCount; ++i) { |
702 for (int i = 0; i < channelCount; ++i) { |
688 if (channels[i].resendCurrent) { |
703 if (channels[i].resendCurrent) { |
689 channels[i].resendCurrent = false; |
704 channels[i].resendCurrent = false; |
690 channels[i].state = QHttpNetworkConnectionChannel::IdleState; |
705 channels[i].state = QHttpNetworkConnectionChannel::IdleState; |
691 if (channels[i].reply) { |
706 |
692 |
707 // if this is not possible, error will be emitted and connection terminated |
693 // if this is not possible, error will be emitted and connection terminated |
708 if (!channels[i].resetUploadData()) |
694 if (!channels[i].resetUploadData()) |
709 continue; |
695 continue; |
710 |
696 |
711 channels[i].sendRequest(); |
697 channels[i].sendRequest(); |
|
698 } |
|
699 } |
712 } |
700 } |
713 } |
701 |
714 |
702 // dequeue new ones |
715 // dequeue new ones |
703 |
716 |
859 #endif |
872 #endif |
860 |
873 |
861 |
874 |
862 // SSL support below |
875 // SSL support below |
863 #ifndef QT_NO_OPENSSL |
876 #ifndef QT_NO_OPENSSL |
864 QSslConfiguration QHttpNetworkConnectionPrivate::sslConfiguration(const QHttpNetworkReply &reply) const |
|
865 { |
|
866 if (!encrypt) |
|
867 return QSslConfiguration(); |
|
868 |
|
869 for (int i = 0; i < channelCount; ++i) |
|
870 if (channels[i].reply == &reply) |
|
871 return static_cast<QSslSocket *>(channels[0].socket)->sslConfiguration(); |
|
872 return QSslConfiguration(); // pending or done request |
|
873 } |
|
874 |
|
875 void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config) |
877 void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config) |
876 { |
878 { |
877 Q_D(QHttpNetworkConnection); |
879 Q_D(QHttpNetworkConnection); |
878 if (!d->encrypt) |
880 if (!d->encrypt) |
879 return; |
881 return; |