Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QWebEngineUrlRequestInterceptor - get headers



  • I'm handling requests by installing QWebEngineUrlRequestInterceptor. That works fine but QWebEngineUrlRequestInfo doesn't have headers() property. I'm only able add new header by QWebEngineUrlRequestInfo::setHttpHeader. I have googled for solution and found that I can also install QWebEngineUrlSchemeHandler but seems that it is not working or it isn't what I expected. I'm initializing as suggested in doc:

    int main(int argc, char *argv[])
    {
        QWebEngineUrlScheme scheme("myscheme");
        scheme.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort);
        scheme.setDefaultPort(2345);
        scheme.setFlags(QWebEngineUrlScheme::SecureScheme);
        QWebEngineUrlScheme::registerScheme(scheme);
    
        QApplication a(argc, argv);
    
        // installUrlSchemeHandler does not take ownership of the handler.
        MySchemeHandler *handler = new MySchemeHandler(&a);
        QWebEngineProfile::defaultProfile()->installUrlSchemeHandler("myscheme", handler);
    
        ....
    }
    

    Header:

    class MySchemeHandler : public QWebEngineUrlSchemeHandler
    {
        Q_OBJECT
    public:
        MySchemeHandler(QObject *parent = nullptr);
        void requestStarted(QWebEngineUrlRequestJob *request) override;
    };
    

    cpp:

    MySchemeHandler::MySchemeHandler(QObject *parent)
        : QWebEngineUrlSchemeHandler(parent)
    {
    
    }
    
    void MySchemeHandler::requestStarted(QWebEngineUrlRequestJob *request)
    {
        qDebug() << "test";
    }
    

    But requestStarted is never triggered



  • Well, now I know, QWebEngineUrlSchemeHandler is for custom scheme only, so for example for myscheme://. If I try to override http:// or https:// then my app is crashing. So, is there any way to intercept http:// / https:// headers? Is it intentionally limited due to security issues or is it not possible because it is encrypted on SSL layer?



  • @Kobid
    Similarly Apple doesn't allow http or https with WKURLSchemeHandler : "A protocol for loading resources with URL schemes that WebKit doesn't know how to handle". https://developer.apple.com/documentation/webkit/wkurlschemehandler

    Sadly no freedom to override internal handlers for "standard" protocols in QWebEngine, no way to manipulate the response, not even to inspect it !
    With CEF you can.


Log in to reply