IQ.Pilot Release Commit @ 27f668a
This commit is contained in:
@@ -44,6 +44,20 @@ def host():
|
||||
|
||||
class TestFileDownload:
|
||||
|
||||
def test_head_connection_released(self, monkeypatch):
|
||||
class Response:
|
||||
status = 200
|
||||
headers = {"content-length": "4"}
|
||||
released = False
|
||||
|
||||
def release_conn(self):
|
||||
self.released = True
|
||||
|
||||
response = Response()
|
||||
monkeypatch.setattr(URLFile, "_request", lambda self, method, url, headers=None: response)
|
||||
assert URLFile("https://example.com/test").get_length_online() == 4
|
||||
assert response.released
|
||||
|
||||
def test_pipeline_defaults(self, host):
|
||||
# TODO: parameterize the defaults so we don't rely on hard-coded values in xx
|
||||
|
||||
|
||||
@@ -128,10 +128,13 @@ class URLFile:
|
||||
|
||||
def get_length_online(self) -> int:
|
||||
response = self._request('HEAD', self._url)
|
||||
if not (200 <= response.status <= 299):
|
||||
return -1
|
||||
length = response.headers.get('content-length', 0)
|
||||
return int(length)
|
||||
try:
|
||||
if not (200 <= response.status <= 299):
|
||||
return -1
|
||||
length = response.headers.get('content-length', 0)
|
||||
return int(length)
|
||||
finally:
|
||||
response.release_conn()
|
||||
|
||||
def get_length(self) -> int:
|
||||
if self._length is not None:
|
||||
|
||||
Reference in New Issue
Block a user