diff options
author | Aleksey Lim <alsroot@sugarlabs.org> | 2013-05-22 04:24:45 (GMT) |
---|---|---|
committer | Aleksey Lim <alsroot@sugarlabs.org> | 2013-05-22 04:24:45 (GMT) |
commit | f4ed41ea3fe45f3d96737117fce9a65c4fd99adc (patch) | |
tree | b0f069b1df9621819eb7361dffc50b79065f12c2 | |
parent | 4995aeb6243c80c638da34f9b903027025e61891 (diff) |
Do not ignore downloads with not specified Content-Length header
-rw-r--r-- | sugar_network/toolkit/http.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sugar_network/toolkit/http.py b/sugar_network/toolkit/http.py index 7186edd..b2d676d 100644 --- a/sugar_network/toolkit/http.py +++ b/sugar_network/toolkit/http.py @@ -21,7 +21,7 @@ from os.path import join, dirname sys.path.insert(0, join(dirname(__file__), '..', 'lib', 'requests')) -from requests import Session, ConnectionError +from requests import Session from requests.exceptions import SSLError from sugar_network import client, toolkit @@ -135,8 +135,11 @@ class Client(object): def download(self, path, dst): response = self.request('GET', path, allow_redirects=True) - content_length = int(response.headers.get('Content-Length', '0')) - chunk_size = min(content_length, BUFFER_SIZE) + content_length = response.headers.get('Content-Length') + if content_length: + chunk_size = min(int(content_length), BUFFER_SIZE) + else: + chunk_size = BUFFER_SIZE f = file(dst, 'wb') if isinstance(dst, basestring) else dst try: for chunk in response.iter_content(chunk_size=chunk_size): |