Skip to content

Commit

Permalink
[downloader:http] close connection when file already exists (#3748)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClosedPort22 committed Aug 8, 2023
1 parent df5c7ee commit 5448268
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gallery_dl/downloader/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ def _download_impl(self, url, pathfmt):
pathfmt.build_path()
if pathfmt.exists():
pathfmt.temppath = ""
# release the connection back to pool by explicitly
# calling .close()
# see https://requests.readthedocs.io/en/latest/user
# /advanced/#body-content-workflow
# when the image size is on the order of megabytes,
# re-establishing a TLS connection will typically be faster
# than consuming the whole response
response.close()
return True
if self.part and metadata:
pathfmt.part_enable(self.partdir)
Expand All @@ -246,6 +254,7 @@ def _download_impl(self, url, pathfmt):
if self._adjust_extension(pathfmt, file_header) and \
pathfmt.exists():
pathfmt.temppath = ""
response.close()
return True

# set open mode
Expand Down

0 comments on commit 5448268

Please sign in to comment.