Skip to content

Commit b3b773f

Browse files
authored
fix: exclude 308s from httplib2 redirect codes list (#813)
1 parent 56ef052 commit b3b773f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

googleapiclient/http.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1886,4 +1886,11 @@ def build_http():
18861886
http_timeout = socket.getdefaulttimeout()
18871887
else:
18881888
http_timeout = DEFAULT_HTTP_TIMEOUT_SEC
1889-
return httplib2.Http(timeout=http_timeout)
1889+
http = httplib2.Http(timeout=http_timeout)
1890+
# 308's are used by several Google APIs (Drive, YouTube)
1891+
# for Resumable Uploads rather than Permanent Redirects.
1892+
# This asks httplib2 to exclude 308s from the status codes
1893+
# it treats as redirects
1894+
http.redirect_codes = http.redirect_codes - {308}
1895+
1896+
return http

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
packages = ["apiclient", "googleapiclient", "googleapiclient/discovery_cache"]
3434

3535
install_requires = [
36-
"httplib2>=0.9.2,<1dev",
36+
"httplib2>=0.17.0,<1dev",
3737
"google-auth>=1.4.1",
3838
"google-auth-httplib2>=0.0.3",
3939
"six>=1.6.1,<2dev",

tests/test_http.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,10 @@ def test_build_http_default_timeout_can_be_set_to_zero(self):
16471647
socket.setdefaulttimeout(0)
16481648
http = build_http()
16491649
self.assertEquals(http.timeout, 0)
1650+
1651+
def test_build_http_default_308_is_excluded_as_redirect(self):
1652+
http = build_http()
1653+
self.assertTrue(308 not in http.redirect_codes)
16501654

16511655

16521656
if __name__ == "__main__":

0 commit comments

Comments
 (0)