Skip to content

Commit

Permalink
Merge pull request #78 from aliyun/fix-reuse-connection
Browse files Browse the repository at this point in the history
fix #79: requests keep-alive works only when response.read() is called to read all body.
  • Loading branch information
yami committed Jun 19, 2017
2 parents e4c01f9 + 6169b23 commit 3dd24a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion oss2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '2.3.2'
__version__ = '2.3.3'

from . import models, exceptions

Expand Down
8 changes: 7 additions & 1 deletion oss2/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def progress_callback(bytes_consumed, total_bytes):
import shutil
import oss2.utils


class _Base(object):
def __init__(self, auth, endpoint, is_cname, session, connect_timeout,
app_name='', enable_crc=True):
Expand All @@ -146,6 +145,13 @@ def _do(self, method, bucket_name, key, **kwargs):
resp = self.session.do_request(req, timeout=self.timeout)
if resp.status // 100 != 2:
raise exceptions.make_exception(resp)

# Note that connections are only released back to the pool for reuse once all body data has been read;
# be sure to either set stream to False or read the content property of the Response object.
# For more details, please refer to http://docs.python-requests.org/en/master/user/advanced/#keep-alive.
content_length = oss2.models._hget(resp.headers, 'content-length', int)
if content_length is not None and content_length == 0:
resp.read()

return resp

Expand Down

0 comments on commit 3dd24a6

Please sign in to comment.