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

QWebEngineUrlResponseInterceptor::setResponseHeaders has no visible effects

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Out of scope
    • Icon: P1: Critical P1: Critical
    • None
    • 6.6.0 Beta3
    • WebEngine
    • None
    • Linux/X11

      1. Added/modified headers do not appear in the dev tools (maybe it is expected as chrome extensions that change headers have the same behavior?)
      2. Modified headers do not have observable effects. For instance forcing Content-Type to text/plain has no effect while it should force chromium to display the HTML source as plain text. Similarly after removing the Content-Security-Policy headers, chromium still enforce them.

       

      For reference here is the code I wrote to test using the simplebrowser demo:

      // webpage.cpp
      class Interceptor : public QWebEngineUrlResponseInterceptor {
      public:
        void interceptResponseHeaders(QWebEngineUrlResponseInfo &info) override;
      };
      
      void Interceptor::interceptResponseHeaders(QWebEngineUrlResponseInfo &info) {
        // only modify headers for the main request
        if (info.requestUrl() != QUrl("https://www.qt.io/"))
          return;
      
        qDebug() << "Changing headers";
        auto headers = info.responseHeaders();
        headers.insert("x-foo", "foobar");
        headers.insert("content-security-policy", "f");
        headers.insert("content-type", "text/plain");
        info.setResponseHeaders(headers);
      }
      
      WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
          : QWebEnginePage(profile, parent) {
        connect(this, &QWebEnginePage::selectClientCertificate, this,
                &WebPage::handleSelectClientCertificate);
        connect(this, &QWebEnginePage::certificateError, this,
                &WebPage::handleCertificateError);
        setUrlResponseInterceptor(new Interceptor);
      }
      

      Note that if I do change the content-type header of all requests, the webpage does appear broken. So at least for some resources (JS or CSS ?) the modified content-type header is recognized.

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

            qt_webengine_team Qt WebEngine Team
            bterrier Benjamin Terrier
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes