Skip to content

Commit

Permalink
Do not load h11 if it's not used
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickaël Guérin committed Jan 14, 2023
1 parent 79becec commit 4ef9150
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 1 addition & 3 deletions uvicorn/config.py
Expand Up @@ -21,8 +21,6 @@
Union,
)

from h11._connection import DEFAULT_MAX_INCOMPLETE_EVENT_SIZE

from uvicorn.logging import TRACE_LOG_LEVEL

if sys.version_info < (3, 8): # pragma: py-gte-38
Expand Down Expand Up @@ -242,7 +240,7 @@ def __init__(
ssl_ciphers: str = "TLSv1",
headers: Optional[List[Tuple[str, str]]] = None,
factory: bool = False,
h11_max_incomplete_event_size: int = DEFAULT_MAX_INCOMPLETE_EVENT_SIZE,
h11_max_incomplete_event_size: Optional[int] = None,
):
self.app = app
self.host = host
Expand Down
7 changes: 3 additions & 4 deletions uvicorn/main.py
Expand Up @@ -7,7 +7,6 @@
import typing

import click
from h11._connection import DEFAULT_MAX_INCOMPLETE_EVENT_SIZE

import uvicorn
from uvicorn.config import (
Expand Down Expand Up @@ -343,7 +342,7 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
"--h11-max-incomplete-event-size",
"h11_max_incomplete_event_size",
type=int,
default=DEFAULT_MAX_INCOMPLETE_EVENT_SIZE,
default=None,
help="For h11, the maximum number of bytes to buffer of an incomplete event.",
)
@click.option(
Expand Down Expand Up @@ -397,7 +396,7 @@ def main(
headers: typing.List[str],
use_colors: bool,
app_dir: str,
h11_max_incomplete_event_size: int,
h11_max_incomplete_event_size: typing.Optional[int],
factory: bool,
) -> None:
run(
Expand Down Expand Up @@ -497,7 +496,7 @@ def run(
use_colors: typing.Optional[bool] = None,
app_dir: typing.Optional[str] = None,
factory: bool = False,
h11_max_incomplete_event_size: int = DEFAULT_MAX_INCOMPLETE_EVENT_SIZE,
h11_max_incomplete_event_size: typing.Optional[int] = None,
) -> None:
if app_dir is not None:
sys.path.insert(0, app_dir)
Expand Down
8 changes: 7 additions & 1 deletion uvicorn/protocols/http/h11_impl.py
Expand Up @@ -6,6 +6,7 @@
from urllib.parse import unquote

import h11
from h11._connection import DEFAULT_MAX_INCOMPLETE_EVENT_SIZE

from uvicorn.config import Config
from uvicorn.logging import TRACE_LOG_LEVEL
Expand Down Expand Up @@ -79,7 +80,12 @@ def __init__(
self.logger = logging.getLogger("uvicorn.error")
self.access_logger = logging.getLogger("uvicorn.access")
self.access_log = self.access_logger.hasHandlers()
self.conn = h11.Connection(h11.SERVER, config.h11_max_incomplete_event_size)
self.conn = h11.Connection(
h11.SERVER,
config.h11_max_incomplete_event_size
if config.h11_max_incomplete_event_size is not None
else DEFAULT_MAX_INCOMPLETE_EVENT_SIZE,
)
self.ws_protocol_class = config.ws_protocol_class
self.root_path = config.root_path
self.limit_concurrency = config.limit_concurrency
Expand Down

0 comments on commit 4ef9150

Please sign in to comment.