fix: exclude 308s from httplib2 redirect codes list (#813)
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index 5b5ea15..719664d 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -1886,4 +1886,11 @@
http_timeout = socket.getdefaulttimeout()
else:
http_timeout = DEFAULT_HTTP_TIMEOUT_SEC
- return httplib2.Http(timeout=http_timeout)
+ http = httplib2.Http(timeout=http_timeout)
+ # 308's are used by several Google APIs (Drive, YouTube)
+ # for Resumable Uploads rather than Permanent Redirects.
+ # This asks httplib2 to exclude 308s from the status codes
+ # it treats as redirects
+ http.redirect_codes = http.redirect_codes - {308}
+
+ return http
diff --git a/setup.py b/setup.py
index 643df2e..617515b 100644
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,7 @@
packages = ["apiclient", "googleapiclient", "googleapiclient/discovery_cache"]
install_requires = [
- "httplib2>=0.9.2,<1dev",
+ "httplib2>=0.17.0,<1dev",
"google-auth>=1.4.1",
"google-auth-httplib2>=0.0.3",
"six>=1.6.1,<2dev",
diff --git a/tests/test_http.py b/tests/test_http.py
index 1b0caa5..2bf5060 100644
--- a/tests/test_http.py
+++ b/tests/test_http.py
@@ -1647,6 +1647,10 @@
socket.setdefaulttimeout(0)
http = build_http()
self.assertEquals(http.timeout, 0)
+
+ def test_build_http_default_308_is_excluded_as_redirect(self):
+ http = build_http()
+ self.assertTrue(308 not in http.redirect_codes)
if __name__ == "__main__":