Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-116167

Duplicate requests of QNetworkAccessManager do not work

    XMLWordPrintable

Details

    • 13c4e11c4 (dev), 44e53b3ed (6.6), 3e1cf8b0a (6.5), 545d6e52d (tqtc/lts-6.2)

    Description

      Please see the code below. Multiple requests of QNetworkAccessManager together to a single URL, where the first two are stopped, but the last one never completes. If you call abort the final one does complete. but there is a workaground , if setting the property of QNetworkRequest object like setAttribute(QNetworkRequest::Http2AllowedAttribute, false); then it works fine.

      #include <QCoreApplication>
      #include <QNetworkAccessManager>
      #include <QNetworkReply>
      #include <QTimer>
      namespace {
          void watch(QNetworkReply *reply, const QString &name)
          {
              QObject::connect(reply, &QNetworkReply::finished, [=]()
              {
                  qInfo() << name << ": finished";
              });
              QObject::connect(reply, &QNetworkReply::destroyed, [=]() {
                  qInfo() << name << ": destroyed";
              });
          }
          void abort(QNetworkReply *reply)
          {
              //reply->abort(); // if you do this it works
              //reply->close(); // if you do this it still does not work
              reply->deleteLater();
          }
      }
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
          QNetworkAccessManager manager;
          QTimer::singleShot(1, [&]() {
              {
                  auto reply = manager.get(QNetworkRequest(QUrl("https://www.google.com/")));
                  watch(reply, "dud1");
                  abort(reply);
              }
              {
                  auto reply = manager.get(QNetworkRequest(QUrl("https://www.google.com/")));
                  watch(reply, "dud2");
                  abort(reply);
              }
              {
                  auto reply = manager.get(QNetworkRequest(QUrl("https://www.google.com/")));
                  watch(reply, "real");
              }
          });
          return a.exec();
      }
      

      Attachments

        For Gerrit Dashboard: QTBUG-116167
        # Subject Branch Project Status CR V

        Activity

          People

            manordheim MÃ¥rten Nordheim
            nigel.lu Nigel Lu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes