Add do-not-track and accept-language headers

This commit is contained in:
Florian Bruhin 2014-05-01 17:54:50 +02:00
parent 31ab264fe8
commit 8556d06ae7
2 changed files with 20 additions and 0 deletions

View File

@ -56,6 +56,7 @@ FIRST_COMMENT = """
SECTION_DESC = {
'general': "General/misc. options",
'input': "Options related to input modes.",
'network': "Settings related to the network.",
'completion': "Options related to completion and command history .",
'tabbar': "Configuration of the tab bar.",
'webkit': "Webkit settings.",
@ -187,6 +188,16 @@ DATA = OrderedDict([
"Use {} for the filename. Gets split via shutils."),
)),
('network', sect.KeyValue(
('do-not-track',
SettingValue(types.Bool(), 'true'),
"Value to send in the DNT header."),
('accept-language',
SettingValue(types.String(), 'en-US,en'),
"Value to send in the accept-language header."),
)),
('completion', sect.KeyValue(
('show',
SettingValue(types.Bool(), 'true'),

View File

@ -19,6 +19,7 @@
from PyQt5.QtNetwork import QNetworkAccessManager
import qutebrowser.config.config as config
from qutebrowser.network.qutescheme import QuteSchemeHandler
@ -63,6 +64,14 @@ class NetworkManager(QNetworkAccessManager):
reply = self._scheme_handlers[scheme].createRequest(
op, req, outgoing_data)
else:
if config.get('network', 'do-not-track'):
dnt = '1'.encode('ascii')
else:
dnt = '0'.encode('ascii')
req.setRawHeader('DNT'.encode('ascii'), dnt)
req.setRawHeader('X-Do-Not-Track'.encode('ascii'), dnt)
req.setRawHeader('Accept-Language'.encode('ascii'),
config.get('network', 'accept-language'))
reply = super().createRequest(op, req, outgoing_data)
self._requests[id(reply)] = reply
reply.destroyed.connect(lambda obj: self._requests.pop(id(obj)))