Add a custom-headers setting

Supersedes #1132
Closes #1020.
This commit is contained in:
Florian Bruhin 2016-04-19 06:21:20 +02:00
parent c5999443a1
commit e860d8cfea
4 changed files with 19 additions and 0 deletions

View File

@ -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
~~~~~~~

View File

@ -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.

View File

@ -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
)),

View File

@ -362,3 +362,10 @@ Feature: Various utility commands.
And I press the key "<Tab>"
And I press the key "<Ctrl-C>"
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