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

QDeclarativeXMLHttpRequest should call onreadystatechange whenever there is new data

    XMLWordPrintable

Details

    Description

      When using an XmlHttpRequest within QML, the onreadystatechange only gets triggered 3 times (upon success): once when the headers have been received, once when loading the body, and once when done. However, if there is a big resource loaded, the event that triggers onreadystatechange should be fired every time there is new data, which is what Chrome and Firefox do.

      To reproduce:

      <html>
      <script type="text/javascript">
              var postman = new XMLHttpRequest();
              postman.open("GET", "http://localhost/path/to/bigfile.txt");
              postman.onreadystatechange = function() {
                  alert("state changed to " + postman.readyState + " status: " + postman.status + " response length: " + postman.responseText.length + " response text:\n" + postman.responseText);
              }
              postman.send();
      </script>
      </html>
      

      And then load this html page from localhost as well (watch out for same-origin-policy).

      Proposed fix:

      diff --git a/src/declarative/qml/qdeclarativexmlhttprequest.cpp b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
      index 3bc9100..5860422 100644
      --- a/src/declarative/qml/qdeclarativexmlhttprequest.cpp
      +++ b/src/declarative/qml/qdeclarativexmlhttprequest.cpp
      @@ -1226,9 +1226,9 @@ void QDeclarativeXMLHttpRequest::downloadProgress(qint64 bytes)
           m_responseEntityBody.append(m_network->readAll());
           if (wasEmpty && !m_responseEntityBody.isEmpty()) {
               m_state = Loading;
      +    }
               QScriptValue cbv = dispatchCallback(&m_me);
               if (cbv.isError()) printError(cbv);
      -    }
       }
       
       void QDeclarativeXMLHttpRequest::error(QNetworkReply::NetworkError error)
      

      Attachments

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

        Activity

          People

            charles Charles Yin (closed Nokia identity) (Inactive)
            phartman Peter Hartmann (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes