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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2024-02-22 15:56:11 -08:00 committed by Tim Abbott
parent a8d056ac3b
commit bf4933942c
1 changed files with 22 additions and 0 deletions

View File

@ -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]"] = []