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

Changing referer for WebEngineView never works.

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Duplicate
    • Affects Version/s: 5.9.0
    • Fix Version/s: None
    • Component/s: WebEngine, WebView
    • Labels:
      None
    • Environment:
      QT 5.9

      Windows 10 64 bit

      MSVC2015_32bit Debug

      Description

      Let me explain a bit of back story.I wanted to change the referer(dynamically) for a webview so I quicky defaulted to the QWebEngineUrlRequestInterceptor. (to basically intercept requests and do the necessary appending of a header).It needed an info to be passed QWebEngineUrlRequestInfo .But i noticed the info didn't have a constructor to I resulted in creating a subclass of the interceptor and have it append headers and intercept request by overriding the interceptrequest function see the code below and a similar implementation here 

      class myinterceptor: public QWebEngineUrlRequestInterceptor
      

       

      void myinterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
      {
          
       
              info.setHttpHeader("Referer", "http://fakereferer.com");
          
      }
      

      But the issue comes in apending the "Referer" header.It simply does not work.All other headers I tested simply work.I am guessing the

       webview->load(); 

      function simply overrides the any referer and simply implements what it deems right(the default referer)

      So that's when I gave up on this option(method) and decide to use  a QWebEngineHttpRequest which i recently so as an addition to QT 5.9 which basically is  a request that you pass into the webview->load(); function.Sounds easy enough....cough cough

      Here is my implementation.

      QString referer ;//stores a referer change dynamically     
      QWebEngineHttpRequest webReq;
           webReq.setUrl(QUrl(my_link));   
           QByteArray byteData = referer.toUtf8();
          webReq.setMethod(QWebEngineHttpRequest::Get);
          webReq.setHeader("Referer",byteData);
          webReq.setHeader("fooo",byteData);//testing random header
          webview->load(webReq);
      
      
      

      The above does not work which is quite frustrating.The referer is not set yet the foo header is set to the value referer(byteData)

      but this works .

      QString referer ;//stores a referer change dynamically     
      QWebEngineHttpRequest webReq;
           webReq.setUrl(QUrl(my_link));   
           
          webReq.setMethod(QWebEngineHttpRequest::Get);
          webReq.setHeader("Referer","http://foo.com");
          
          webview->load(webReq);
      

      So the ACTUAL BUG comes down to passing QByteArray to the  setHeader method when the header name is "Referer".

      In addition to solving the bug,I would like to ask if the is away to change referer that works. Even ifs too dirty.

       

       

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              qt_webengine_team Qt WebEngine Team
              Reporter:
              updatesvc James May
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes