Allow to not send the DNT header

This commit is contained in:
Florian Bruhin 2017-07-03 15:57:22 +02:00
parent 040be60697
commit 5ada3606d8
4 changed files with 21 additions and 6 deletions

View File

@ -33,9 +33,12 @@ class CallSuper(Exception):
def custom_headers():
"""Get the combined custom headers."""
headers = {}
dnt = b'1' if config.val.content.headers.do_not_track else b'0'
headers[b'DNT'] = dnt
headers[b'X-Do-Not-Track'] = dnt
dnt_config = config.val.content.headers.do_not_track
if dnt_config is not None:
dnt = b'1' if dnt_config else b'0'
headers[b'DNT'] = dnt
headers[b'X-Do-Not-Track'] = dnt
for header, value in config.val.content.headers.custom.items():
headers[header.encode('ascii')] = value.encode('ascii')

View File

@ -225,13 +225,15 @@ content.headers.custom:
desc: Set custom headers for qutebrowser HTTP requests.
content.headers.do_not_track:
type: Bool
type:
name: Bool
none_ok: true
default: true
desc: >-
Value to send in the `DNT` header.
When this is set to true, qutebrowser asks websites to not track your
identity.
identity. If set to null, the DNT header is not sent at all.
content.headers.referer:
default: same-domain

View File

@ -499,7 +499,11 @@ def check_header(quteproc, header, value):
content = quteproc.get_content()
data = json.loads(content)
print(data)
assert utils.pattern_match(pattern=value, value=data['headers'][header])
if value == '<unset>':
assert header not in data['headers']
else:
actual = data['headers'][header]
assert utils.pattern_match(pattern=value, value=actual)
@bdd.then(bdd.parsers.parse('the page should contain the html "{text}"'))

View File

@ -335,6 +335,12 @@ Feature: Various utility commands.
Then the header Dnt should be set to 0
And the header X-Do-Not-Track should be set to 0
Scenario: DNT header (unset)
When I set content.headers.do_not_track to <empty>
And I open headers
Then the header Dnt should be set to <unset>
And the header X-Do-Not-Track should be set to <unset>
Scenario: Accept-Language header
When I set content.headers.accept_language to en,de
And I open headers