mirror of
https://github.com/zvx-echo6/meshai.git
synced 2026-05-22 07:34:47 +02:00
feat: Add User-Agent header to API requests
Adds MeshAI/x.x User-Agent for good API citizenship and easier traffic identification by Meshview/MeshMonitor operators. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a7c409e406
commit
5c8aeb3974
2 changed files with 14 additions and 1 deletions
|
|
@ -8,8 +8,12 @@ from typing import Optional
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
|
from .. import __version__
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
USER_AGENT = f"MeshAI/{__version__}"
|
||||||
|
|
||||||
|
|
||||||
class MeshMonitorDataSource:
|
class MeshMonitorDataSource:
|
||||||
"""Fetches mesh data from a MeshMonitor instance."""
|
"""Fetches mesh data from a MeshMonitor instance."""
|
||||||
|
|
@ -122,6 +126,7 @@ class MeshMonitorDataSource:
|
||||||
headers = {
|
headers = {
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"Authorization": f"Bearer {self._api_token}",
|
"Authorization": f"Bearer {self._api_token}",
|
||||||
|
"User-Agent": USER_AGENT,
|
||||||
}
|
}
|
||||||
try:
|
try:
|
||||||
req = Request(url, headers=headers)
|
req = Request(url, headers=headers)
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,12 @@ from typing import Optional
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
from urllib.request import Request, urlopen
|
from urllib.request import Request, urlopen
|
||||||
|
|
||||||
|
from .. import __version__
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
USER_AGENT = f"MeshAI/{__version__}"
|
||||||
|
|
||||||
|
|
||||||
class MeshviewSource:
|
class MeshviewSource:
|
||||||
"""Fetches mesh data from a Meshview instance."""
|
"""Fetches mesh data from a Meshview instance."""
|
||||||
|
|
@ -75,8 +79,12 @@ class MeshviewSource:
|
||||||
Parsed JSON data or None on error
|
Parsed JSON data or None on error
|
||||||
"""
|
"""
|
||||||
url = f"{self._url}{endpoint}"
|
url = f"{self._url}{endpoint}"
|
||||||
|
headers = {
|
||||||
|
"Accept": "application/json",
|
||||||
|
"User-Agent": USER_AGENT,
|
||||||
|
}
|
||||||
try:
|
try:
|
||||||
req = Request(url, headers={"Accept": "application/json"})
|
req = Request(url, headers=headers)
|
||||||
with urlopen(req, timeout=15) as resp:
|
with urlopen(req, timeout=15) as resp:
|
||||||
return json.loads(resp.read().decode("utf-8"))
|
return json.loads(resp.read().decode("utf-8"))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue