mirror of
https://github.com/home-assistant/supervisor.git
synced 2025-07-24 09:36:31 +00:00
Support upload streaming (#1362)
* Support upload streaming * Fix header * Fix typing
This commit is contained in:
parent
ee76317392
commit
a92cab48e0
@ -8,7 +8,6 @@ from aiohttp import web
|
||||
from aiohttp.web_exceptions import HTTPBadGateway, HTTPUnauthorized
|
||||
from aiohttp.client_exceptions import ClientConnectorError
|
||||
from aiohttp.hdrs import CONTENT_TYPE, AUTHORIZATION
|
||||
import async_timeout
|
||||
|
||||
from ..const import HEADER_HA_ACCESS
|
||||
from ..coresys import CoreSysAttributes
|
||||
@ -17,6 +16,9 @@ from ..exceptions import HomeAssistantAuthError, HomeAssistantAPIError, APIError
|
||||
_LOGGER: logging.Logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
LEGACY_HEADER = ("X-Speech-Content",)
|
||||
|
||||
|
||||
class APIProxy(CoreSysAttributes):
|
||||
"""API Proxy for Home Assistant."""
|
||||
|
||||
@ -43,20 +45,16 @@ class APIProxy(CoreSysAttributes):
|
||||
async def _api_client(self, request: web.Request, path: str, timeout: int = 300):
|
||||
"""Return a client request with proxy origin for Home Assistant."""
|
||||
try:
|
||||
# read data
|
||||
with async_timeout.timeout(30):
|
||||
data = await request.read()
|
||||
|
||||
if data:
|
||||
content_type = request.content_type
|
||||
else:
|
||||
content_type = None
|
||||
|
||||
async with self.sys_homeassistant.make_request(
|
||||
request.method.lower(),
|
||||
f"api/{path}",
|
||||
content_type=content_type,
|
||||
data=data,
|
||||
headers={
|
||||
name: value
|
||||
for name, value in request.headers.items()
|
||||
if name in LEGACY_HEADER
|
||||
},
|
||||
content_type=request.content_type,
|
||||
data=request.content,
|
||||
timeout=timeout,
|
||||
params=request.query,
|
||||
) as resp:
|
||||
|
@ -487,13 +487,14 @@ class HomeAssistant(JsonConfig, CoreSysAttributes):
|
||||
path: str,
|
||||
json: Optional[Dict[str, Any]] = None,
|
||||
content_type: Optional[str] = None,
|
||||
data: Optional[bytes] = None,
|
||||
data: Any = None,
|
||||
timeout: int = 30,
|
||||
params: Optional[Dict[str, str]] = None,
|
||||
headers: Optional[Dict[str, str]] = None,
|
||||
) -> AsyncContextManager[aiohttp.ClientResponse]:
|
||||
"""Async context manager to make a request with right auth."""
|
||||
url = f"{self.api_url}/{path}"
|
||||
headers = {}
|
||||
headers = headers or {}
|
||||
|
||||
# Passthrough content type
|
||||
if content_type is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user