diff --git a/qutebrowser/test/utils/http/test_http.py b/qutebrowser/test/utils/http/test_http.py index 7ee660905..7eb857b99 100644 --- a/qutebrowser/test/utils/http/test_http.py +++ b/qutebrowser/test/utils/http/test_http.py @@ -63,47 +63,5 @@ class ParseContentTypeTests(unittest.TestCase): self.assertEqual(rest, ' encoding=UTF-8') -class ChangeContentTypeTests(unittest.TestCase): - - """Test for change_content_type.""" - - def test_not_existing(self): - """Test without any Content-Type header.""" - reply = FakeNetworkReply() - httputils.change_content_type(reply, {'image/example': 'image/jpeg'}) - - def test_mimetype(self): - """Test with simple Content-Type header.""" - reply = FakeNetworkReply(headers={'Content-Type': 'image/example'}) - httputils.change_content_type(reply, {'image/example': 'image/jpeg'}) - self.assertEqual(reply.headers['Content-Type'], 'image/jpeg') - - def test_empty(self): - """Test with empty Content-Type header.""" - reply = FakeNetworkReply(headers={'Content-Type': ''}) - httputils.change_content_type(reply, {'image/example': 'image/jpeg'}) - self.assertEqual(reply.headers['Content-Type'], '') - - def test_additional(self): - """Test with Content-Type header with additional informations.""" - reply = FakeNetworkReply( - headers={'Content-Type': 'image/example; encoding=UTF-8'}) - httputils.change_content_type(reply, {'image/example': 'image/jpeg'}) - self.assertEqual(reply.headers['Content-Type'], - 'image/jpeg; encoding=UTF-8') - - def test_wrong_mapping(self): - """Test with a mapping which doesn't match the header.""" - reply = FakeNetworkReply(headers={'Content-Type': 'image/example'}) - httputils.change_content_type(reply, {'image/foo': 'image/bar'}) - self.assertEqual(reply.headers['Content-Type'], 'image/example') - - def test_empty_mapping(self): - """Test with a mapping which is empty.""" - reply = FakeNetworkReply(headers={'Content-Type': 'image/example'}) - httputils.change_content_type(reply, {}) - self.assertEqual(reply.headers['Content-Type'], 'image/example') - - if __name__ == '__main__': unittest.main() diff --git a/qutebrowser/utils/http.py b/qutebrowser/utils/http.py index d7d2f17f9..91a6c9173 100644 --- a/qutebrowser/utils/http.py +++ b/qutebrowser/utils/http.py @@ -84,27 +84,3 @@ def parse_content_type(reply): ret = [content_type, None] ret[0] = ret[0].strip() return ret - - -def change_content_type(reply, mapping): - """Change a content-type of a QNetworkReply. - - Args: - reply: The QNetworkReply to handle. - mapping: A mapping of source to target content types. - - Return: - None (modifies the passed reply). - """ - content_type, rest = parse_content_type(reply) - if content_type is None: - return - try: - content_type = mapping[content_type] - except KeyError: - return - if rest is not None: - header = ';'.join((content_type, rest)) - else: - header = content_type - reply.setHeader(QNetworkRequest.ContentTypeHeader, header)