Wrapped HTTP responses in async context managers to prevent connection leaks.
This commit is contained in:
@@ -69,15 +69,9 @@ class OwncastClient:
|
||||
|
||||
# Make a request to the endpoint
|
||||
try:
|
||||
response = await self.session.request(
|
||||
async with self.session.request(
|
||||
"GET", status_url, allow_redirects=False
|
||||
)
|
||||
except Exception as e:
|
||||
self.log.warning(
|
||||
f"[{domain}] Error making GET request to {OWNCAST_STATUS_PATH}: {e}"
|
||||
)
|
||||
return None
|
||||
|
||||
) as response:
|
||||
# Check the response code is success
|
||||
if response.status != 200:
|
||||
self.log.warning(
|
||||
@@ -97,6 +91,11 @@ class OwncastClient:
|
||||
f"interpreted as JSON: {e}"
|
||||
)
|
||||
return None
|
||||
except Exception as e:
|
||||
self.log.warning(
|
||||
f"[{domain}] Error making GET request to {OWNCAST_STATUS_PATH}: {e}"
|
||||
)
|
||||
return None
|
||||
|
||||
# Validate the response contains all basic info needed
|
||||
required_fields = [
|
||||
@@ -130,15 +129,9 @@ class OwncastClient:
|
||||
|
||||
# Make a request to the endpoint
|
||||
try:
|
||||
response = await self.session.request(
|
||||
async with self.session.request(
|
||||
"GET", config_url, allow_redirects=False
|
||||
)
|
||||
except Exception as e:
|
||||
self.log.warning(
|
||||
f"[{domain}] Error making GET request to {OWNCAST_CONFIG_PATH}: {e}"
|
||||
)
|
||||
return None
|
||||
|
||||
) as response:
|
||||
# Check the response code is success
|
||||
if response.status != 200:
|
||||
self.log.warning(
|
||||
@@ -158,6 +151,11 @@ class OwncastClient:
|
||||
f"interpreted as JSON: {e}"
|
||||
)
|
||||
return None
|
||||
except Exception as e:
|
||||
self.log.warning(
|
||||
f"[{domain}] Error making GET request to {OWNCAST_CONFIG_PATH}: {e}"
|
||||
)
|
||||
return None
|
||||
|
||||
# Create StreamConfig from response (fields are truncated to max lengths)
|
||||
return StreamConfig.from_api_response(config)
|
||||
|
||||
Reference in New Issue
Block a user