From 5ada3606d88f5ee629fcd808f92e6bcaa9303204 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 3 Jul 2017 15:57:22 +0200 Subject: [PATCH] Allow to not send the DNT header --- qutebrowser/browser/shared.py | 9 ++++++--- qutebrowser/config/configdata.yml | 6 ++++-- tests/end2end/features/conftest.py | 6 +++++- tests/end2end/features/misc.feature | 6 ++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/qutebrowser/browser/shared.py b/qutebrowser/browser/shared.py index 68157ebf9..5aafb39f5 100644 --- a/qutebrowser/browser/shared.py +++ b/qutebrowser/browser/shared.py @@ -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') diff --git a/qutebrowser/config/configdata.yml b/qutebrowser/config/configdata.yml index 348ef253c..132ec3594 100644 --- a/qutebrowser/config/configdata.yml +++ b/qutebrowser/config/configdata.yml @@ -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 diff --git a/tests/end2end/features/conftest.py b/tests/end2end/features/conftest.py index 0b8e309c8..af9f3e997 100644 --- a/tests/end2end/features/conftest.py +++ b/tests/end2end/features/conftest.py @@ -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 == '': + 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}"')) diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index 37b65b621..82decfe6d 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -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 + And I open headers + Then the header Dnt should be set to + And the header X-Do-Not-Track should be set to + Scenario: Accept-Language header When I set content.headers.accept_language to en,de And I open headers