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

Setting up new application proxy doesn't affect on visited urls

    XMLWordPrintable

Details

    Description

      If programmatically set up application proxy (in my case: http proxy with basic auth) with invalid password and then create request to any valid url (for example, http://qt.nokia.com/), request will fail with 407 status code - this is predictable behaviour.
      But if after that set up application proxy with the same type, host, port, username, but another password (valid) and then create request to the same url (http://qt.nokia.com/), request will fail again. However, if you create request to any other url (not http://qt.nokia.com/) you will succeed.

      I think the problem is in QNAM cached credentials for visited urls.

      Below you can see code sample to reproduce bug.

      void TestClass::testProxy()
      {
      	QString host = "10.103.9.107";
      	quint16 port = 8888;
      	QString username = "user";
      	QString validPass = "password";
      	QString invalidPass = "invalidPassword";
      
      	nam = new QNetworkAccessManager(this);
      
      	QNetworkProxy invalidProxy(QNetworkProxy::HttpProxy, host, port, username, invalidPass);
      	QNetworkProxy validProxy(invalidProxy);
      	validProxy.setPassword(validPass);
      
      	QUrl url1("http://www.google.ru/");
      	QUrl url2("http://ya.ru/");
      
      	// first step
      	QNetworkProxy::setApplicationProxy(invalidProxy);
      	QNetworkRequest request1(url1);
      	QNetworkReply *reply1 = nam->get(request1);
      	this->connect(reply1, SIGNAL(finished()), SLOT(processFinished()));
      
      	// second step
      	QNetworkProxy::setApplicationProxy(validProxy);
      	QNetworkRequest request2(url2);
      	QNetworkReply *reply2 = nam->get(request2);
      	this->connect(reply2, SIGNAL(finished()), SLOT(processFinished()));
      
      	// third step
      	QNetworkRequest request3(url1);
      	QNetworkReply *reply3 = nam->get(request3);
      	this->connect(reply3, SIGNAL(finished()), SLOT(processFinished()));
      }
      
      void TestClass::processFinished()
      {
      	QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
      
      	qDebug() << reply->url().toString();
      	qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
      	qDebug() << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
      }
      
      

      In the application output window you can see:

      QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://user@10.103.9.107:8888#*'
      QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://user@10.103.9.107:8888'
      QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://10.103.9.107:8888'

      "http://www.google.ru/"
      407
      "Proxy Authentication Required"

      "http://www.google.ru/"
      0
      ""

      "http://ya.ru/"
      200
      "OK"

      If you interchange "validProxy" and "invalidProxy" in code sample (in setApplicationProxy() calls) you will see next:

      "http://ya.ru/"
      407
      "Proxy Authentication Required"

      "http://www.google.ru/"
      200
      "OK"

      "http://www.google.ru/"
      200
      "OK"

      This is unpredictable behaviour again. The second request to http://www.google.ru/ (in step 3) must be failed because of invalid proxy settings.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            temppost2 Ivan Shestakov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes