Author: johnnyg
Revision: 6096
Log:
Completely disable gzip decoding when allow_compression=False. Add
extra test.
Diff:
Modified: trunk/deluge/httpdownloader.py
===================================================================
--- trunk/deluge/httpdownloader.py 2010-01-16 04:21:25 UTC (rev 6095)
+++ trunk/deluge/httpdownloader.py 2010-01-16 04:50:01 UTC (rev 6096)
@@ -45,7 +45,7 @@
"""
Factory class for downloading files and keeping track of progress.
"""
- def __init__(self, url, filename, part_callback=None, headers=None,
force_filename=False):
+ def __init__(self, url, filename, part_callback=None, headers=None,
force_filename=False, allow_compression=True):
"""
:param url: the url to download from
:type url: string
@@ -62,6 +62,7 @@
self.decoder = None
self.value = filename
self.force_filename = force_filename
+ self.allow_compression = allow_compression
agent = "Deluge/%s (http://deluge-torrent.org)" % get_version()
client.HTTPDownloader.__init__(self, url, filename, headers=headers,
agent=agent)
@@ -76,7 +77,8 @@
else:
self.total_length = 0
- if "content-encoding" in headers and
headers["content-encoding"][0] in ("gzip", "x-gzip", "deflate"):
+ if self.allow_compression and "content-encoding" in headers and \
+ headers["content-encoding"][0] in ("gzip", "x-gzip", "deflate"):
# Adding 32 to the wbits enables gzip & zlib decoding (with
automatic header detection)
# Adding 16 just enables gzip decoding (no zlib)
self.decoder = zlib.decompressobj(zlib.MAX_WBITS + 32)
@@ -186,7 +188,7 @@
headers["accept-encoding"] = "gzip, deflate"
scheme, host, port, path = client._parse(url)
- factory = HTTPDownloader(url, filename, callback, headers, force_filename)
+ factory = HTTPDownloader(url, filename, callback, headers, force_filename,
allow_compression)
if scheme == "https":
from twisted.internet import ssl
reactor.connectSSL(host, port, factory, ssl.ClientContextFactory())
Modified: trunk/tests/test_httpdownloader.py
===================================================================
--- trunk/tests/test_httpdownloader.py 2010-01-16 04:21:25 UTC (rev 6095)
+++ trunk/tests/test_httpdownloader.py 2010-01-16 04:50:01 UTC (rev 6096)
@@ -17,10 +17,22 @@
f = open(filename)
try:
self.assertEqual(f.read(), contents)
+ except Exception, e:
+ self.fail(e)
finally:
f.close()
return filename
+ def failIfContains(self, filename, contents):
+ f = open(filename)
+ try:
+ self.failIfEqual(f.read(), contents)
+ except Exception, e:
+ self.fail(e)
+ finally:
+ f.close()
+ return filename
+
def test_download(self):
d = download_file("http://deluge-torrent.org", "index.html")
d.addCallback(self.assertEqual, "index.html")
@@ -75,6 +87,12 @@
d.addCallback(self.assertContains, "success")
return d
+ def test_download_with_gzip_encoding_disabled(self):
+ url = "http://deluge-torrent.org/httpdownloader.php?test=gzip&msg=fail"
+ d = download_file(url, "gzip_encoded", allow_compression=False)
+ d.addCallback(self.failIfContains, "fail")
+ return d
+
def test_page_redirect(self):
url = "http://deluge-torrent.org/httpdownloader.php?test=redirect"
d = download_file(url, "none")
--
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en.