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

User-Agent set via QWebEngineUrlRequestInterceptor is ignored for reloads

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 6.11.0 FF
    • 6.5.3, 6.9.2
    • WebEngine
    • None
    • ec2ad7c97 (dev)

      When visiting https://httpbin.io/redirect-to?url=https://httpbin.io/headers and setting a custom User-Agent header via QWebEngineUrlRequestInterceptor (so that the header can be overridden differently for different websites), since Qt 6.5 the header does not get applied after a redirect. Other headers seem to be set correctly.

      Minimal example:

      #include <QApplication>
      #include <QWebEngineView>
      #include <QWebEngineProfile>
      #include <QWebEngineUrlRequestInterceptor>
      #include <QWebEngineUrlRequestInfo>
      #include <QTimer>
      #include <QUrl>
      
      class RequestInterceptor : public QWebEngineUrlRequestInterceptor {
      public:
          using QWebEngineUrlRequestInterceptor::QWebEngineUrlRequestInterceptor;
          void interceptRequest(QWebEngineUrlRequestInfo &info) override {
              info.setHttpHeader("X-Test", "test-value");
              info.setHttpHeader("Accept", "test-value");
              info.setHttpHeader("User-Agent", "test-value");
          }
      };
      
      int main(int argc, char *argv[]) {
          QApplication app(argc, argv);
      
          auto interceptor = new RequestInterceptor(&app);
          QWebEngineProfile::defaultProfile()->setUrlRequestInterceptor(interceptor);
      
          auto wv = new QWebEngineView;
          wv->load(QUrl("https://httpbin.io/redirect-to?url=https://httpbin.io/headers"));
          wv->show();
      
          QTimer::singleShot(5000, wv, &QWebEngineView::reload);
      
          return app.exec();
      }
      
      QT += widgets webenginewidgets
      SOURCES += headers.cpp
      TARGET = headers
      

      Before the refresh:

          "Accept": [
            "test-value"
          ],
          "User-Agent": [
            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/6.9.2 Chrome/130.0.0.0 Safari/537.36"
          ],
          "X-Test": [
            "test-value"
          ],
      

      after the refresh:

          "Accept": [
            "test-value"
          ],
          "User-Agent": [
            "test-value"
          ],
          "X-Test": [
            "test-value"
          ],
      

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

            kchehlarski Kaloyan Chehlarski
            the compiler Florian Bruhin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes