This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interceptor.cpp
71 lines (68 loc) · 2.72 KB
/
interceptor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "interceptor.h"
URLRequestInterceptor::URLRequestInterceptor(QObject *parent) :
QWebEngineUrlRequestInterceptor(parent)
{}
void URLRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
qInfo() << "outgoing request";
qInfo().noquote() << "method:" << info.requestMethod();
qInfo().noquote() << " url:" << info.requestUrl().toString();
qInfo().noquote() << " type:" << resourceTypeString(info.resourceType());
if(info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame){
qInfo() << "request allowed";
info.block(false);
return;
}
qWarning() << "request blocked";
info.block(true);
}
const QString URLRequestInterceptor::resourceTypeString(QWebEngineUrlRequestInfo::ResourceType type)
{
switch (type) {
case QWebEngineUrlRequestInfo::ResourceTypeMainFrame:
return "Main Frame";
case QWebEngineUrlRequestInfo::ResourceTypeSubFrame:
return "Sub Frame";
case QWebEngineUrlRequestInfo::ResourceTypeStylesheet:
return "Stylesheet";
case QWebEngineUrlRequestInfo::ResourceTypeScript:
return "Script";
case QWebEngineUrlRequestInfo::ResourceTypeImage:
return "Image";
case QWebEngineUrlRequestInfo::ResourceTypeFontResource:
return "Font Resource";
case QWebEngineUrlRequestInfo::ResourceTypeSubResource:
return "Sub Resource";
case QWebEngineUrlRequestInfo::ResourceTypeObject:
return "Object";
case QWebEngineUrlRequestInfo::ResourceTypeMedia:
return "Media";
case QWebEngineUrlRequestInfo::ResourceTypeWorker:
return "Worker";
case QWebEngineUrlRequestInfo::ResourceTypeSharedWorker:
return "Shared Worker";
case QWebEngineUrlRequestInfo::ResourceTypePrefetch:
return "Prefetch";
case QWebEngineUrlRequestInfo::ResourceTypeFavicon:
return "Favicon";
case QWebEngineUrlRequestInfo::ResourceTypeXhr:
return "XHR";
case QWebEngineUrlRequestInfo::ResourceTypePing:
return "Ping";
case QWebEngineUrlRequestInfo::ResourceTypeServiceWorker:
return "Service Worker";
case QWebEngineUrlRequestInfo::ResourceTypeCspReport:
return "CSP Report";
case QWebEngineUrlRequestInfo::ResourceTypePluginResource:
return "Plugin Resource";
case QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadMainFrame:
return "Navigation Preload Main Frame";
case QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadSubFrame:
return "Navigation Preload Sub Frame";
case QWebEngineUrlRequestInfo::ResourceTypeWebSocket:
return "Web Socket";
case QWebEngineUrlRequestInfo::ResourceTypeUnknown:
return "Unknown";
}
return "Unsupported";
}