Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

run-dev: Abbreviate error message when receiving an https request.

Anders Kaseorgbf4933942ca8
diff --git a/tools/run-dev b/tools/run-dev
index 9963e4ac3de..1998b66db65 100755
--- a/tools/run-dev
+++ b/tools/run-dev
@@ -20,6 +20,7 @@ sanity_check.check_venv(__file__)
import aiohttp
from aiohttp import hdrs, web
+from aiohttp.http_exceptions import BadStatusLine
from returns.curry import partial
from tools.lib.test_script import add_provision_check_override_param, assert_provisioning_status_ok
@@ -306,6 +307,27 @@ def print_listeners() -> None:
print()
+def https_log_filter(record: logging.LogRecord) -> bool:
+ # aiohttp emits an exception with a traceback when receiving an
+ # https request (https://github.com/aio-libs/aiohttp/issues/8065).
+ # Abbreviate it to a one-line message.
+ if (
+ record.exc_info is not None
+ and isinstance(error := record.exc_info[1], BadStatusLine)
+ and error.message.startswith(
+ (
+ "Invalid method encountered:\n\n b'\\x16",
+ 'Invalid method encountered:\n\n b"\\x16',
+ )
+ )
+ ):
+ record.msg = "Rejected https request (this development server only supports http)"
+ record.exc_info = None
+ return True
+
+
+logging.getLogger("aiohttp.server").addFilter(https_log_filter)
+
runner: web.AppRunner
children: List["subprocess.Popen[bytes]"] = []