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

XMLHttpRequest populates responseText with 301 Moved Permanently intermediate content

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.2.1
    • None
    • Qt 5.2.1 on Linux Mint 16

    Description

      Doing an XMLHttpRequest to an URL which responds with a 301 Moved Permanently redirect, causes the responseText to be populated with both the content of the redirect page as well as the final result.

      import QtQuick 2.2
      
      Item {
        Component.onCompleted: {
          var ajax = new XMLHttpRequest
          ajax.open("get", "http://path/to/the/script/below")
          ajax.onreadystatechange = function() {
            if (ajax.readyState === XMLHttpRequest.DONE) {
              console.log(ajax.responseText)
            }
          }
          ajax.send()
        }
      }
      

      Place this on a server and use it in the ajax.open function:

      <?php
          if ($_GET["test"] == "yes") {
              echo "But this text should";
          } else {
              header("HTTP/1.1 301 Moved Permanently");
              header("Location: " . $_SERVER["PHP_SELF"] . "?test=yes");
      
              echo "This should not be part of the responseText";
          }
      ?>
      

      The result will be This should not be part of the responseTextBut this text should instead of But this text should.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            w00t Robin Burchell
            broulik Kai Uwe Broulik
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes