summaryrefslogtreecommitdiff
path: root/python2/httplib2/__init__.py
diff options
context:
space:
mode:
authorJoe Gregorio <jcgregorio@google.com>2013-03-08 14:14:56 -0500
committerJoe Gregorio <jcgregorio@google.com>2013-03-08 14:14:56 -0500
commit1d3a7099b0e8b9a2dc62e59bf9c3deac55087ac6 (patch)
tree0ba55d7e7aa7e064edf1b75487c5645ff669a93d /python2/httplib2/__init__.py
parentfdfd04a15a6d1ef9212df009cd252d49cf41e94e (diff)
downloadhttplib2-1d3a7099b0e8b9a2dc62e59bf9c3deac55087ac6.tar.gz
Fix handling of BadStatusLine.
Fixes issue #250. Review in https://codereview.appspot.com/7529045/.
Diffstat (limited to 'python2/httplib2/__init__.py')
-rw-r--r--python2/httplib2/__init__.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py
index 9780d4e..191ef1e 100644
--- a/python2/httplib2/__init__.py
+++ b/python2/httplib2/__init__.py
@@ -1246,7 +1246,10 @@ class Http(object):
self.authorizations = []
def _conn_request(self, conn, request_uri, method, body, headers):
- for i in range(RETRIES):
+ i = 0
+ seen_bad_status_line = False
+ while i < RETRIES:
+ i += 1
try:
if hasattr(conn, 'sock') and conn.sock is None:
conn.connect()
@@ -1284,6 +1287,19 @@ class Http(object):
continue
try:
response = conn.getresponse()
+ except httplib.BadStatusLine:
+ # If we get a BadStatusLine on the first try then that means
+ # the connection just went stale, so retry regardless of the
+ # number of RETRIES set.
+ if not seen_bad_status_line and i == 1:
+ i = 0
+ seen_bad_status_line = True
+ conn.close()
+ conn.connect()
+ continue
+ else:
+ conn.close()
+ raise
except (socket.error, httplib.HTTPException):
if i < RETRIES-1:
conn.close()