Make user agent configurable

This commit is contained in:
Florian Bruhin 2014-05-02 06:54:46 +02:00
parent bb70fa1c5a
commit 678abca244
3 changed files with 13 additions and 1 deletions

1
TODO
View File

@ -32,7 +32,6 @@ history
Minor features Minor features
============== ==============
set useragent
show current value in setting completions show current value in setting completions
handle completion for aliases handle completion for aliases
keybind should have completion for commands/arguments keybind should have completion for commands/arguments

View File

@ -22,6 +22,7 @@ from PyQt5.QtNetwork import QNetworkReply
from PyQt5.QtWebKitWidgets import QWebPage from PyQt5.QtWebKitWidgets import QWebPage
import qutebrowser.utils.url as urlutils import qutebrowser.utils.url as urlutils
import qutebrowser.config.config as config
from qutebrowser.network.networkmanager import NetworkManager from qutebrowser.network.networkmanager import NetworkManager
from qutebrowser.utils.misc import read_file from qutebrowser.utils.misc import read_file
@ -69,6 +70,14 @@ class BrowserPage(QWebPage):
title=title, url=urlstr, error=info.errorString, icon='') title=title, url=urlstr, error=info.errorString, icon='')
return True return True
def userAgentForUrl(self, url):
"""Override QWebPage::userAgentForUrl to customize the user agent."""
ua = config.get('network', 'user-agent')
if not ua:
return super().userAgentForUrl(url)
else:
return ua
def supportsExtension(self, ext): def supportsExtension(self, ext):
"""Override QWebPage::supportsExtension to provide error pages. """Override QWebPage::supportsExtension to provide error pages.

View File

@ -201,6 +201,10 @@ DATA = OrderedDict([
('accept-language', ('accept-language',
SettingValue(types.String(), 'en-US,en'), SettingValue(types.String(), 'en-US,en'),
"Value to send in the accept-language header."), "Value to send in the accept-language header."),
('user-agent',
SettingValue(types.String(), ''),
"User agent to send. Empty to send the default."),
)), )),
('completion', sect.KeyValue( ('completion', sect.KeyValue(