Commit 14b9e0ad authored by Jérome Perrin's avatar Jérome Perrin

software/caddy-frontend/test: use resource.Session as context manager

this prevents ResourceWarning because this way the sockets are closed
parent 03c55402
...@@ -499,6 +499,7 @@ def fakeHTTPSResult(domain, path, port=HTTPS_PORT, ...@@ -499,6 +499,7 @@ def fakeHTTPSResult(domain, path, port=HTTPS_PORT,
headers.setdefault('Via', 'http/1.1 clientvia') headers.setdefault('Via', 'http/1.1 clientvia')
session = requests.Session() session = requests.Session()
with session:
if source_ip is not None: if source_ip is not None:
new_source = source.SourceAddressAdapter(source_ip) new_source = source.SourceAddressAdapter(source_ip)
session.mount('http://', new_source) session.mount('http://', new_source)
...@@ -541,6 +542,7 @@ def fakeHTTPResult(domain, path, port=HTTP_PORT, ...@@ -541,6 +542,7 @@ def fakeHTTPResult(domain, path, port=HTTP_PORT,
headers.setdefault('Via', 'http/1.1 clientvia') headers.setdefault('Via', 'http/1.1 clientvia')
headers['Host'] = '%s:%s' % (domain, port) headers['Host'] = '%s:%s' % (domain, port)
session = requests.Session() session = requests.Session()
with session:
if source_ip is not None: if source_ip is not None:
new_source = source.SourceAddressAdapter(source_ip) new_source = source.SourceAddressAdapter(source_ip)
session.mount('http://', new_source) session.mount('http://', new_source)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment