- same_domain: If the tld is unknown, only return True if the hostnames are the same
- Fix when starting without an open page
This commit is contained in:
Martin Tournoij 2015-06-27 21:14:19 +02:00
parent f806eefba6
commit a346644c71
3 changed files with 15 additions and 6 deletions

View File

@ -21,9 +21,10 @@
import collections import collections
from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, QCoreApplication) from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, QCoreApplication,
QUrl, QByteArray)
from PyQt5.QtNetwork import (QNetworkAccessManager, QNetworkReply, QSslError, from PyQt5.QtNetwork import (QNetworkAccessManager, QNetworkReply, QSslError,
QSslSocket, QUrl, QByteArray) QSslSocket)
from qutebrowser.config import config from qutebrowser.config import config
from qutebrowser.utils import (message, log, usertypes, utils, objreg, qtutils, from qutebrowser.utils import (message, log, usertypes, utils, objreg, qtutils,
@ -339,12 +340,14 @@ class NetworkManager(QNetworkAccessManager):
current_url = objreg.get('tabbed-browser', scope='window', current_url = objreg.get('tabbed-browser', scope='window',
window=self._win_id).currentWidget().url() window=self._win_id).currentWidget().url()
if (config.get('network', 'referer-header') == 'never' or if config.get('network', 'referer-header') == 'never':
(config.get('network', 'referer-header') == 'same-domain' and
urlutils.same_domain(req.url(), current_url))):
# Note: using ''.encode('ascii') sends a header with no value, # Note: using ''.encode('ascii') sends a header with no value,
# instead of no header at all # instead of no header at all
req.setRawHeader('Referer'.encode('ascii'), QByteArray()) req.setRawHeader('Referer'.encode('ascii'), QByteArray())
elif (config.get('network', 'referer-header') == 'same-domain' and
current_url.isValid() and
not urlutils.same_domain(req.url(), current_url)):
req.setRawHeader('Referer'.encode('ascii'), QByteArray())
accept_language = config.get('network', 'accept-language') accept_language = config.get('network', 'accept-language')
if accept_language is not None: if accept_language is not None:

View File

@ -411,6 +411,9 @@ def same_domain(url1, url2):
suffix1 = url1.topLevelDomain() suffix1 = url1.topLevelDomain()
suffix2 = url2.topLevelDomain() suffix2 = url2.topLevelDomain()
if suffix1 == '':
return url1.host() == url2.host()
if not suffix1 == suffix2: if not suffix1 == suffix2:
return False return False

View File

@ -239,6 +239,8 @@ class TestSameDomain:
('http://example.com', 'http://www.example.com'), ('http://example.com', 'http://www.example.com'),
('http://bbc.co.uk', 'https://www.bbc.co.uk'), ('http://bbc.co.uk', 'https://www.bbc.co.uk'),
('http://many.levels.of.domains.example.com', 'http://www.example.com'), ('http://many.levels.of.domains.example.com', 'http://www.example.com'),
('http://idn.иком.museum', 'http://idn2.иком.museum'),
('http://one.not_a_valid_tld', 'http://one.not_a_valid_tld'),
) )
for host1, host2 in hosts: for host1, host2 in hosts:
@ -250,7 +252,8 @@ class TestSameDomain:
hosts = ( hosts = (
('http://bbc.co.uk', 'http://example.co.uk'), ('http://bbc.co.uk', 'http://example.co.uk'),
('https://example.kids.museum', 'http://example.kunst.museum'), ('https://example.kids.museum', 'http://example.kunst.museum'),
('http://idn.иком.museum', 'http://idn.ירושלים.museum') ('http://idn.иком.museum', 'http://idn.ירושלים.museum'),
('http://one.not_a_valid_tld', 'http://two.not_a_valid_tld'),
) )
for host1, host2 in hosts: for host1, host2 in hosts: