Support upload streaming (#1362)

* Support upload streaming

* Fix header

* Fix typing
This commit is contained in:
Pascal Vizeli
2019-11-06 23:57:51 +01:00
committed by GitHub
parent ee76317392
commit a92cab48e0
2 changed files with 13 additions and 14 deletions

View File

@@ -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: