Skip to content

Commit

Permalink
feat: reuse tcp connection
Browse files Browse the repository at this point in the history
As per the documentation of `requests`, a connection won't be released
until `content` is read from `Response`. This commit adds dummy reads
at proper positions.
  • Loading branch information
Blaok committed Jun 3, 2018
1 parent 440c613 commit 8f1408c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions easywebdav/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def cd(self, path):

def mkdir(self, path, safe=False):
expected_codes = 201 if not safe else (201, 301, 405)
self._send('MKCOL', path, expected_codes)
self._send('MKCOL', path, expected_codes).content

def mkdirs(self, path):
dirs = [d for d in path.split('/') if d]
Expand All @@ -144,10 +144,10 @@ def mkdirs(self, path):
def rmdir(self, path, safe=False):
path = str(path).rstrip('/') + '/'
expected_codes = 204 if not safe else (204, 404)
self._send('DELETE', path, expected_codes)
self._send('DELETE', path, expected_codes).content

def delete(self, path):
self._send('DELETE', path, 204)
self._send('DELETE', path, 204).content

def upload(self, local_path_or_fileobj, remote_path):
if isinstance(local_path_or_fileobj, basestring):
Expand All @@ -157,7 +157,7 @@ def upload(self, local_path_or_fileobj, remote_path):
self._upload(local_path_or_fileobj, remote_path)

def _upload(self, fileobj, remote_path):
self._send('PUT', remote_path, (200, 201, 204), data=fileobj)
self._send('PUT', remote_path, (200, 201, 204), data=fileobj).content

def download(self, remote_path, local_path_or_fileobj):
response = self._send('GET', remote_path, 200, stream=True)
Expand Down Expand Up @@ -185,4 +185,5 @@ def ls(self, remote_path='.'):

def exists(self, remote_path):
response = self._send('HEAD', remote_path, (200, 301, 404))
response.content
return True if response.status_code != 404 else False

0 comments on commit 8f1408c

Please sign in to comment.