Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade request handling: ignore http/2 and optionally ignore websocket #1661

Merged
merged 13 commits into from Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/deployment.md
Expand Up @@ -69,8 +69,8 @@ Options:
--ws-per-message-deflate BOOLEAN
WebSocket per-message-deflate compression
[default: True]
--ws-ignore-upgrade Upgrade requests will be ignored and
answered with normal HTTP responses
--ws-ignore-upgrade Upgrade requests will be ignored, and
HTTP/1.1 will continue to be used
--lifespan [auto|on|off] Lifespan implementation. [default: auto]
--interface [auto|asgi3|asgi2|wsgi]
Select ASGI3, ASGI2, or WSGI as the
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Expand Up @@ -136,8 +136,8 @@ Options:
--ws-per-message-deflate BOOLEAN
WebSocket per-message-deflate compression
[default: True]
--ws-ignore-upgrade Upgrade requests will be ignored and
answered with normal HTTP responses
--ws-ignore-upgrade Upgrade requests will be ignored, and
HTTP/1.1 will continue to be used
--lifespan [auto|on|off] Lifespan implementation. [default: auto]
--interface [auto|asgi3|asgi2|wsgi]
Select ASGI3, ASGI2, or WSGI as the
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/main.py
Expand Up @@ -173,7 +173,7 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
"--ws-ignore-upgrade",
type=bool,
Kludex marked this conversation as resolved.
Show resolved Hide resolved
default=False,
help="Upgrade requests will be ignored and answered with normal HTTP responses",
help="Upgrade requests will be ignored, and HTTP/1.1 will continue to be used",
Kludex marked this conversation as resolved.
Show resolved Hide resolved
show_default=True,
is_flag=True,
)
Expand Down
4 changes: 2 additions & 2 deletions uvicorn/protocols/http/h11_impl.py
Expand Up @@ -220,7 +220,7 @@ def handle_events(self) -> None:
}

if self._should_upgrade(event):
self.handle_upgrade(event)
self.handle_websocket_upgrade(event)
return

# Handle 503 responses when 'limit_concurrency' is exceeded.
Expand Down Expand Up @@ -266,7 +266,7 @@ def handle_events(self) -> None:
self.cycle.more_body = False
self.cycle.message_event.set()

def handle_upgrade(self, event: H11Event) -> None:
def handle_websocket_upgrade(self, event: H11Event) -> None:
if self.ws_protocol_class is None:
msg = "Unsupported upgrade request."
self.logger.warning(msg)
Expand Down
4 changes: 2 additions & 2 deletions uvicorn/protocols/http/httptools_impl.py
Expand Up @@ -176,9 +176,9 @@ def data_received(self, data: bytes) -> None:
return
except httptools.HttpParserUpgrade:
if self._should_upgrade():
self.handle_upgrade()
self.handle_websocket_upgrade()

def handle_upgrade(self) -> None:
def handle_websocket_upgrade(self) -> None:
if self.ws_protocol_class is None:
msg = "Unsupported upgrade request."
self.logger.warning(msg)
Expand Down