Refactor former network section
This commit is contained in:
parent
f1d81d86aa
commit
129ee33ffb
@ -44,7 +44,7 @@ class ProxyFactory(QNetworkProxyFactory):
|
|||||||
Return:
|
Return:
|
||||||
None if proxy is correct, otherwise an error message.
|
None if proxy is correct, otherwise an error message.
|
||||||
"""
|
"""
|
||||||
proxy = config.val.network.proxy
|
proxy = config.val.content.proxy
|
||||||
if isinstance(proxy, pac.PACFetcher):
|
if isinstance(proxy, pac.PACFetcher):
|
||||||
return proxy.fetch_error()
|
return proxy.fetch_error()
|
||||||
else:
|
else:
|
||||||
@ -59,7 +59,7 @@ class ProxyFactory(QNetworkProxyFactory):
|
|||||||
Return:
|
Return:
|
||||||
A list of QNetworkProxy objects in order of preference.
|
A list of QNetworkProxy objects in order of preference.
|
||||||
"""
|
"""
|
||||||
proxy = config.val.network.proxy
|
proxy = config.val.content.proxy
|
||||||
if proxy is configtypes.SYSTEM_PROXY:
|
if proxy is configtypes.SYSTEM_PROXY:
|
||||||
proxies = QNetworkProxyFactory.systemProxyForQuery(query)
|
proxies = QNetworkProxyFactory.systemProxyForQuery(query)
|
||||||
elif isinstance(proxy, pac.PACFetcher):
|
elif isinstance(proxy, pac.PACFetcher):
|
||||||
@ -69,7 +69,7 @@ class ProxyFactory(QNetworkProxyFactory):
|
|||||||
for p in proxies:
|
for p in proxies:
|
||||||
if p.type() != QNetworkProxy.NoProxy:
|
if p.type() != QNetworkProxy.NoProxy:
|
||||||
capabilities = p.capabilities()
|
capabilities = p.capabilities()
|
||||||
if config.val.network.proxy_dns_requests:
|
if config.val.content.proxy_dns_requests:
|
||||||
capabilities |= QNetworkProxy.HostNameLookupCapability
|
capabilities |= QNetworkProxy.HostNameLookupCapability
|
||||||
else:
|
else:
|
||||||
capabilities &= ~QNetworkProxy.HostNameLookupCapability
|
capabilities &= ~QNetworkProxy.HostNameLookupCapability
|
||||||
|
@ -35,16 +35,16 @@ class CallSuper(Exception):
|
|||||||
def custom_headers():
|
def custom_headers():
|
||||||
"""Get the combined custom headers."""
|
"""Get the combined custom headers."""
|
||||||
headers = {}
|
headers = {}
|
||||||
dnt = b'1' if config.val.network.do_not_track else b'0'
|
dnt = b'1' if config.val.content.do_not_track else b'0'
|
||||||
headers[b'DNT'] = dnt
|
headers[b'DNT'] = dnt
|
||||||
headers[b'X-Do-Not-Track'] = dnt
|
headers[b'X-Do-Not-Track'] = dnt
|
||||||
|
|
||||||
config_headers = config.val.network.custom_headers
|
config_headers = config.val.content.custom_headers
|
||||||
if config_headers is not None:
|
if config_headers is not None:
|
||||||
for header, value in config_headers.items():
|
for header, value in config_headers.items():
|
||||||
headers[header.encode('ascii')] = value.encode('ascii')
|
headers[header.encode('ascii')] = value.encode('ascii')
|
||||||
|
|
||||||
accept_language = config.val.network.accept_language
|
accept_language = config.val.content.accept_language
|
||||||
if accept_language is not None:
|
if accept_language is not None:
|
||||||
headers[b'Accept-Language'] = accept_language.encode('ascii')
|
headers[b'Accept-Language'] = accept_language.encode('ascii')
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ def ignore_certificate_errors(url, errors, abort_on):
|
|||||||
Return:
|
Return:
|
||||||
True if the error should be ignored, False otherwise.
|
True if the error should be ignored, False otherwise.
|
||||||
"""
|
"""
|
||||||
ssl_strict = config.val.network.ssl_strict
|
ssl_strict = config.val.content.ssl_strict
|
||||||
log.webview.debug("Certificate errors {!r}, strict {}".format(
|
log.webview.debug("Certificate errors {!r}, strict {}".format(
|
||||||
errors, ssl_strict))
|
errors, ssl_strict))
|
||||||
|
|
||||||
|
@ -63,6 +63,6 @@ class RequestInterceptor(QWebEngineUrlRequestInterceptor):
|
|||||||
for header, value in shared.custom_headers():
|
for header, value in shared.custom_headers():
|
||||||
info.setHttpHeader(header, value)
|
info.setHttpHeader(header, value)
|
||||||
|
|
||||||
user_agent = config.val.network.user_agent
|
user_agent = config.val.conent.user_agent
|
||||||
if user_agent is not None:
|
if user_agent is not None:
|
||||||
info.setHttpHeader(b'User-Agent', user_agent.encode('ascii'))
|
info.setHttpHeader(b'User-Agent', user_agent.encode('ascii'))
|
||||||
|
@ -163,8 +163,7 @@ def _set_user_agent(profile):
|
|||||||
per-domain user agents), but this one still gets used for things like
|
per-domain user agents), but this one still gets used for things like
|
||||||
window.navigator.userAgent in JS.
|
window.navigator.userAgent in JS.
|
||||||
"""
|
"""
|
||||||
user_agent = config.val.network.user_agent
|
profile.setHttpUserAgent(config.val.content.user_agent)
|
||||||
profile.setHttpUserAgent(user_agent)
|
|
||||||
|
|
||||||
|
|
||||||
def update_settings(section, option):
|
def update_settings(section, option):
|
||||||
|
@ -274,7 +274,7 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
# altogether.
|
# altogether.
|
||||||
reply.netrc_used = True
|
reply.netrc_used = True
|
||||||
try:
|
try:
|
||||||
net = netrc.netrc(config.val.network.netrc_file)
|
net = netrc.netrc(config.val.content.netrc_file)
|
||||||
authenticators = net.authenticators(reply.url().host())
|
authenticators = net.authenticators(reply.url().host())
|
||||||
if authenticators is not None:
|
if authenticators is not None:
|
||||||
(user, _account, password) = authenticators
|
(user, _account, password) = authenticators
|
||||||
@ -338,7 +338,7 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
|
|
||||||
def set_referer(self, req, current_url):
|
def set_referer(self, req, current_url):
|
||||||
"""Set the referer header."""
|
"""Set the referer header."""
|
||||||
referer_header_conf = config.val.network.referer_header
|
referer_header_conf = config.val.content.referer_header
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if referer_header_conf == 'never':
|
if referer_header_conf == 'never':
|
||||||
|
@ -384,7 +384,7 @@ class BrowserPage(QWebPage):
|
|||||||
|
|
||||||
def userAgentForUrl(self, url):
|
def userAgentForUrl(self, url):
|
||||||
"""Override QWebPage::userAgentForUrl to customize the user agent."""
|
"""Override QWebPage::userAgentForUrl to customize the user agent."""
|
||||||
ua = config.val.network.user_agent
|
ua = config.val.content.user_agent
|
||||||
if ua is None:
|
if ua is None:
|
||||||
return super().userAgentForUrl(url)
|
return super().userAgentForUrl(url)
|
||||||
else:
|
else:
|
||||||
|
@ -417,7 +417,7 @@ def run_async(tab, cmd, *args, win_id, env, verbose=False):
|
|||||||
lambda cmd:
|
lambda cmd:
|
||||||
log.commands.debug("Got userscript command: {}".format(cmd)))
|
log.commands.debug("Got userscript command: {}".format(cmd)))
|
||||||
runner.got_cmd.connect(commandrunner.run_safely)
|
runner.got_cmd.connect(commandrunner.run_safely)
|
||||||
user_agent = config.val.network.user_agent
|
user_agent = config.val.content.user_agent
|
||||||
if user_agent is not None:
|
if user_agent is not None:
|
||||||
env['QUTE_USER_AGENT'] = user_agent
|
env['QUTE_USER_AGENT'] = user_agent
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user