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

Use path with query string on WebSockets logs #1385

Merged
merged 2 commits into from Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions uvicorn/protocols/websockets/websockets_impl.py
Expand Up @@ -15,7 +15,12 @@

from uvicorn.config import Config
from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn.protocols.utils import get_local_addr, get_remote_addr, is_ssl
from uvicorn.protocols.utils import (
get_local_addr,
get_path_with_query_string,
get_remote_addr,
is_ssl,
)
from uvicorn.server import ServerState

if sys.version_info < (3, 8):
Expand Down Expand Up @@ -254,7 +259,7 @@ async def asgi_send(self, message: "ASGISendEvent") -> None:
self.logger.info(
'%s - "WebSocket %s" [accepted]',
self.scope["client"],
self.scope["path"],
get_path_with_query_string(self.scope),
)
self.initial_response = None
self.accepted_subprotocol = cast(
Expand All @@ -274,7 +279,7 @@ async def asgi_send(self, message: "ASGISendEvent") -> None:
self.logger.info(
'%s - "WebSocket %s" 403',
self.scope["client"],
self.scope["path"],
get_path_with_query_string(self.scope),
)
self.initial_response = (http.HTTPStatus.FORBIDDEN, [], b"")
self.handshake_started_event.set()
Expand Down
11 changes: 8 additions & 3 deletions uvicorn/protocols/websockets/wsproto_impl.py
Expand Up @@ -10,7 +10,12 @@
from wsproto.utilities import RemoteProtocolError

from uvicorn.logging import TRACE_LOG_LEVEL
from uvicorn.protocols.utils import get_local_addr, get_remote_addr, is_ssl
from uvicorn.protocols.utils import (
get_local_addr,
get_path_with_query_string,
get_remote_addr,
is_ssl,
)


class WSProtocol(asyncio.Protocol):
Expand Down Expand Up @@ -244,7 +249,7 @@ async def send(self, message):
self.logger.info(
'%s - "WebSocket %s" [accepted]',
self.scope["client"],
self.scope["path"],
get_path_with_query_string(self.scope),
)
self.handshake_complete = True
subprotocol = message.get("subprotocol")
Expand All @@ -266,7 +271,7 @@ async def send(self, message):
self.logger.info(
'%s - "WebSocket %s" 403',
self.scope["client"],
self.scope["path"],
get_path_with_query_string(self.scope),
)
self.handshake_complete = True
self.close_sent = True
Expand Down