Fix webserver config for the Home Assistant add-on (#758)
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sun, 9 Jul 2023 19:31:44 +0000 (21:31 +0200)
committerGitHub <noreply@github.com>
Sun, 9 Jul 2023 19:31:44 +0000 (21:31 +0200)
* unhide the expose option for the webserver

* Set some sane defaults on the webserver

* use correct hassio network

music_assistant/server/controllers/webserver.py
music_assistant/server/helpers/webserver.py

index b5be4b4e9fe53c2434927023ad5993a6bdc5234e..9bccfa59c7b9667b79c817611d5a1e32537680ad 100644 (file)
@@ -95,7 +95,6 @@ class WebserverController(CoreController):
                     f"http://{default_publish_ip}:8095 to access the webinterface. \n\n"
                     "Use this option on your own risk and never expose this port "
                     "directly to the internet.",
-                    hidden=True,
                 ),
             )
 
@@ -174,9 +173,9 @@ class WebserverController(CoreController):
                 bind_ip = "0.0.0.0"
                 self.publish_ip = default_publish_ip
             else:
-                # use internal (172.x) IP
+                # use internal ("172.30.32.) IP
                 self.publish_ip = bind_ip = next(
-                    (x for x in await get_ips() if x.startswith("172")), default_publish_ip
+                    (x for x in await get_ips() if x.startswith("172.30.32.")), default_publish_ip
                 )
             base_url = f"http://{self.publish_ip}:{self.publish_port}"
         else:
index 785c9727af90b1a4862ce043d463930246401ece..dd60ebd3027d7def117bbc3cc529a11c1be639f5 100644 (file)
@@ -3,9 +3,13 @@ from __future__ import annotations
 
 import logging
 from collections.abc import Awaitable, Callable
+from typing import Final
 
 from aiohttp import web
 
+MAX_CLIENT_SIZE: Final = 1024**2 * 16
+MAX_LINE_SIZE: Final = 24570
+
 
 class Webserver:
     """Base Webserver logic for an HTTPServer that can handle dynamic routes."""
@@ -37,8 +41,15 @@ class Webserver:
         self._base_url = base_url[:-1] if base_url.endswith("/") else base_url
         self._bind_port = bind_port
         self._static_routes = static_routes
-        self._webapp = web.Application(logger=self.logger)
-        self.logger.debug("Starting server on  %s:%s - base url: %s", bind_ip, bind_port, base_url)
+        self._webapp = web.Application(
+            logger=self.logger,
+            client_max_size=MAX_CLIENT_SIZE,
+            handler_args={
+                "max_line_size": MAX_LINE_SIZE,
+                "max_field_size": MAX_LINE_SIZE,
+            },
+        )
+        self.logger.info("Starting server on  %s:%s - base url: %s", bind_ip, bind_port, base_url)
         self._apprunner = web.AppRunner(self._webapp, access_log=None)
         # add static routes
         if self._static_routes:
@@ -54,7 +65,9 @@ class Webserver:
         await self._apprunner.setup()
         # set host to None to bind to all addresses on both IPv4 and IPv6
         host = None if bind_ip == "0.0.0.0" else bind_ip
-        self._tcp_site = web.TCPSite(self._apprunner, host=host, port=bind_port)
+        self._tcp_site = web.TCPSite(
+            self._apprunner, host=host, port=bind_port, shutdown_timeout=10
+        )
         await self._tcp_site.start()
 
     async def close(self) -> None: