QWebEngineUrlRequestInfo Class

The QWebEngineUrlRequestInfo class provides information about URL requests. More...

Header: #include <QWebEngineUrlRequestInfo>
CMake: find_package(Qt6 REQUIRED COMPONENTS WebEngineCore)
target_link_libraries(mytarget PRIVATE Qt6::WebEngineCore)
qmake: QT += webenginecore

Public Types

enum NavigationType { NavigationTypeLink, NavigationTypeTyped, NavigationTypeFormSubmitted, NavigationTypeBackForward, NavigationTypeReload, …, NavigationTypeOther }
enum ResourceType { ResourceTypeMainFrame, ResourceTypeSubFrame, ResourceTypeStylesheet, ResourceTypeScript, ResourceTypeImage, …, ResourceTypeUnknown }

Public Functions

void block(bool shouldBlock)
QUrl firstPartyUrl() const
(since 6.5) QHash<QByteArray, QByteArray> httpHeaders() const
QUrl initiator() const
QWebEngineUrlRequestInfo::NavigationType navigationType() const
void redirect(const QUrl &url)
(since 6.7) QIODevice *requestBody() const
QByteArray requestMethod() const
QUrl requestUrl() const
QWebEngineUrlRequestInfo::ResourceType resourceType() const
void setHttpHeader(const QByteArray &name, const QByteArray &value)

Detailed Description

The QWebEngineUrlRequestInfo is useful for setting extra header fields for requests or for redirecting certain requests without payload data to another URL. This class cannot be instantiated or copied by the user, instead it will be created by Qt WebEngine and sent through the virtual function QWebEngineUrlRequestInterceptor::interceptRequest() if an interceptor has been set.

Member Type Documentation

This enum type describes the navigation type of the request:

ConstantValueDescription
QWebEngineUrlRequestInfo::NavigationTypeLink0Navigation initiated by clicking a link.
QWebEngineUrlRequestInfo::NavigationTypeTyped1Navigation explicitly initiated by typing a URL.
QWebEngineUrlRequestInfo::NavigationTypeFormSubmitted2Navigation submits a form.
QWebEngineUrlRequestInfo::NavigationTypeBackForward3Navigation initiated by a history action.
QWebEngineUrlRequestInfo::NavigationTypeReload4Navigation initiated by refreshing the page.
QWebEngineUrlRequestInfo::NavigationTypeRedirect6Navigation triggered automatically by page content or remote server. (Added in Qt 5.14)
QWebEngineUrlRequestInfo::NavigationTypeOther5None of the above.

enum QWebEngineUrlRequestInfo::ResourceType

This enum type holds the type of the requested resource:

ConstantValueDescription
QWebEngineUrlRequestInfo::ResourceTypeMainFrame0Top level page.
QWebEngineUrlRequestInfo::ResourceTypeSubFrame1Frame or iframe.
QWebEngineUrlRequestInfo::ResourceTypeStylesheet2A CSS stylesheet.
QWebEngineUrlRequestInfo::ResourceTypeScript3An external script.
QWebEngineUrlRequestInfo::ResourceTypeImage4An image (JPG, GIF, PNG, and so on).
QWebEngineUrlRequestInfo::ResourceTypeFontResource5A font.
QWebEngineUrlRequestInfo::ResourceTypeSubResource6An "other" subresource.
QWebEngineUrlRequestInfo::ResourceTypeObject7An object (or embed) tag for a plugin or a resource that a plugin requested.
QWebEngineUrlRequestInfo::ResourceTypeMedia8A media resource.
QWebEngineUrlRequestInfo::ResourceTypeWorker9The main resource of a dedicated worker.
QWebEngineUrlRequestInfo::ResourceTypeSharedWorker10The main resource of a shared worker.
QWebEngineUrlRequestInfo::ResourceTypePrefetch11An explicitly requested prefetch.
QWebEngineUrlRequestInfo::ResourceTypeFavicon12A favicon.
QWebEngineUrlRequestInfo::ResourceTypeXhr13An XMLHttpRequest.
QWebEngineUrlRequestInfo::ResourceTypePing14A ping request for <a ping>.
QWebEngineUrlRequestInfo::ResourceTypeServiceWorker15The main resource of a service worker.
QWebEngineUrlRequestInfo::ResourceTypeCspReport16A report of Content Security Policy (CSP) violations. CSP reports are in JSON format and they are delivered by HTTP POST requests to specified servers. (Added in Qt 5.7)
QWebEngineUrlRequestInfo::ResourceTypePluginResource17A resource requested by a plugin. (Added in Qt 5.7)
QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadMainFrame19A main-frame service worker navigation preload request. (Added in Qt 5.14)
QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadSubFrame20A sub-frame service worker navigation preload request. (Added in Qt 5.14)
QWebEngineUrlRequestInfo::ResourceTypeWebSocket254A WebSocket request. (Added in Qt 6.4)
QWebEngineUrlRequestInfo::ResourceTypeUnknown255Unknown request type.

Note: For forward compatibility all values not matched should be treated as unknown, not just ResourceTypeUnknown.

Member Function Documentation

void QWebEngineUrlRequestInfo::block(bool shouldBlock)

Blocks this request if shouldBlock is true, so that it will not proceed.

This function can be used to prevent navigating away from a given domain, for example.

QUrl QWebEngineUrlRequestInfo::firstPartyUrl() const

Returns the first party URL of the request. The first party URL is the URL of the page that issued the request.

[since 6.5] QHash<QByteArray, QByteArray> QWebEngineUrlRequestInfo::httpHeaders() const

Returns the request headers.

Note: Not all headers are visible at this stage as Chromium will add security and proxy headers at a later stage.

This function was introduced in Qt 6.5.

QUrl QWebEngineUrlRequestInfo::initiator() const

Returns the origin URL of the document that initiated the navigation of a frame to another frame.

Returns the navigation type of the request.

See also NavigationType.

void QWebEngineUrlRequestInfo::redirect(const QUrl &url)

Redirects this request to url.

[since 6.7] QIODevice *QWebEngineUrlRequestInfo::requestBody() const

Returns a pointer to a QIODevice that gives access to the request body. The request body can contain data for example when the request is a POST request. If the request body is empty the QIODevice reflects this and does not return any data when performing read operations on it.

This function was introduced in Qt 6.7.

QByteArray QWebEngineUrlRequestInfo::requestMethod() const

Returns the HTTP method of the request (for example, GET or POST).

QUrl QWebEngineUrlRequestInfo::requestUrl() const

Returns the requested URL.

QWebEngineUrlRequestInfo::ResourceType QWebEngineUrlRequestInfo::resourceType() const

Returns the resource type of the request.

See also ResourceType.

void QWebEngineUrlRequestInfo::setHttpHeader(const QByteArray &name, const QByteArray &value)

Sets the request header name to value for this request.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.