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

QNetworkRequest ignores QUrl::password() when QUrl::userName() contains a whitespace

    XMLWordPrintable

Details

    Description

      When creating a QNetworkRequest from a QUrl that contains a userInfo, it automatically triggers an HTTP Basic Auth. As long as the user name contains no whitespaces, everything works fine:

      QNetworkRequest req(QUrl("http://TestUser:testpw@localhost/"));
      
      ... start the request ...
      
      (Server receives user name "TestUser" and password "testpw")
      

      However, when the QUrl::userName() contains a whitespace, an empty password is transmitted to the server:

      QNetworkRequest req(QUrl("http://Test%20User:testpw@localhost/"));
      
      ... start the request ...
      
      (Server receives user name "TestUser" and password "")
      

      I'm currently using the following workaround, providing the "Authorization" header by hand:

      QNetworkRequest req(QUrl("http://localhost/"));
      req.setRawHeader("Authorization", "Basic " + QByteArray("Test User:testpw").toBase64());
      
      ... start the request ...
      
      (Server receives user name "TestUser" and password "testpw")
      

      But I don't think this is the intended way of providing authorization.

      Attachments

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

        Activity

          People

            xizzhu Xizhi Zhu (Steven)
            vog Volker Grabsch
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes