Use the following redirects feature of httplib2 where it returns the ultimate
URL in the content-location header to follow redirects for media download.
http://httplib2.googlecode.com/hg/doc/html/libhttplib2.html#response-objects
Reviewed in https://codereview.appspot.com/10393046/
Fixes issue #280.
diff --git a/apiclient/http.py b/apiclient/http.py
index 31a1c44..f518d87 100644
--- a/apiclient/http.py
+++ b/apiclient/http.py
@@ -508,8 +508,6 @@
self._progress = 0
self._total_size = None
self._done = False
- self._original_follow_redirects = request.http.follow_redirects
- request.http.follow_redirects = False
# Stubs for testing.
self._sleep = time.sleep
@@ -551,10 +549,9 @@
if resp.status < 500:
break
- if resp.status in [301, 302, 303, 307, 308] and 'location' in resp:
- self._uri = resp['location']
- resp, content = http.request(self._uri, headers=headers)
if resp.status in [200, 206]:
+ if 'content-location' in resp and resp['content-location'] != self._uri:
+ self._uri = resp['content-location']
self._progress += len(content)
self._fd.write(content)
@@ -565,7 +562,6 @@
if self._progress == self._total_size:
self._done = True
- self._request.http.follow_redirects = self._original_follow_redirects
return MediaDownloadProgress(self._progress, self._total_size), self._done
else:
raise HttpError(resp, content, uri=self._uri)