Skip to content

Commit

Permalink
Use path with query string on WebSockets logs (#1385)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
  • Loading branch information
levrik and Kludex committed Sep 11, 2022
1 parent f258adf commit e2164fb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
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

0 comments on commit e2164fb

Please sign in to comment.