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