From e860d8cfea229f0f66394528696a277db1aef834 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 19 Apr 2016 06:21:20 +0200 Subject: [PATCH] Add a custom-headers setting Supersedes #1132 Closes #1020. --- CHANGELOG.asciidoc | 1 + qutebrowser/browser/network/networkmanager.py | 7 +++++++ qutebrowser/config/configdata.py | 4 ++++ tests/integration/features/misc.feature | 7 +++++++ 4 files changed, 19 insertions(+) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index ce3c7a59d..5ff06602c 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -21,6 +21,7 @@ Added ~~~~~ - New `:edit-url` command to edit the URL in an external editor. +- New `network -> custom-headers` setting to send custom headers with every request. Changed ~~~~~~~ diff --git a/qutebrowser/browser/network/networkmanager.py b/qutebrowser/browser/network/networkmanager.py index a222f2713..1156c0c9e 100644 --- a/qutebrowser/browser/network/networkmanager.py +++ b/qutebrowser/browser/network/networkmanager.py @@ -398,6 +398,13 @@ class NetworkManager(QNetworkAccessManager): req.setRawHeader('DNT'.encode('ascii'), dnt) req.setRawHeader('X-Do-Not-Track'.encode('ascii'), dnt) + # Load custom headers + custom_headers = config.get('network', 'custom-headers') + + if custom_headers is not None: + for header, value in custom_headers.items(): + req.setRawHeader(header.encode('ascii'), value.encode('ascii')) + # There are some scenarios where we can't figure out current_url: # - There's a generic NetworkManager, e.g. for downloads # - The download was in a tab which is now closed. diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index 10dad1ce9..b98b1b1c9 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -401,6 +401,10 @@ def data(readonly=False): SettingValue(typ.Bool(), 'true'), "Whether to try to pre-fetch DNS entries to speed up browsing."), + ('custom-headers', + SettingValue(typ.HeaderDict(none_ok=True), ''), + "Set custom headers for qutebrowser HTTP requests."), + readonly=readonly )), diff --git a/tests/integration/features/misc.feature b/tests/integration/features/misc.feature index 8f0ab8014..991560b7a 100644 --- a/tests/integration/features/misc.feature +++ b/tests/integration/features/misc.feature @@ -362,3 +362,10 @@ Feature: Various utility commands. And I press the key "" And I press the key "" Then no crash should happen + + ## Custom headers + + Scenario: Setting a custom header + When I set network -> custom-headers to {"X-Qute-Test": "testvalue"} + And I open headers + Then the header X-Qute-Test should be set to testvalue