Repository: encode/uvicorn

Issue:
Remove superfluous `root_path` from logging messages
### Checklist

- [X] The bug is reproducible against the latest release or `master`.
- [X] There are no similar issues or pull requests to fix it yet.

### Describe the bug

As per https://github.com/encode/starlette/issues/1336, `scope["root_path"]` is never supposed to be joined to `scope["path"]`, as the latter is supposed to be already prefixed with the former. Luckily uvicorn is never doing this _except_ in logging. It is logging incorrect paths (according to ASGI spec) in the following places:

https://github.com/encode/uvicorn/blob/master/uvicorn/protocols/websockets/wsproto_impl.py#L256
https://github.com/encode/uvicorn/blob/master/uvicorn/protocols/websockets/wsproto_impl.py#L272
https://github.com/encode/uvicorn/blob/master/uvicorn/protocols/websockets/websockets_impl.py#L230
https://github.com/encode/uvicorn/blob/master/uvicorn/protocols/websockets/websockets_impl.py#L240
https://github.com/encode/uvicorn/blob/master/uvicorn/protocols/utils.py#L50

### Steps to reproduce the bug

_No response_

### Expected behavior

_No response_

### Actual behavior

_No response_

### Debugging material

_No response_

### Environment

Running uvicorn 0.16.0 with CPython 3.8.10 on Darwin

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/uvicorn/protocols/utils.py b/uvicorn/protocols/utils.py
--- a/uvicorn/protocols/utils.py
+++ b/uvicorn/protocols/utils.py
@@ -46,9 +46,7 @@ def get_client_addr(scope: WWWScope) -> str:
 
 
 def get_path_with_query_string(scope: WWWScope) -> str:
-    path_with_query_string = urllib.parse.quote(
-        scope.get("root_path", "") + scope["path"]
-    )
+    path_with_query_string = urllib.parse.quote(scope["path"])
     if scope["query_string"]:
         path_with_query_string = "{}?{}".format(
             path_with_query_string, scope["query_string"].decode("ascii")
diff --git a/uvicorn/protocols/websockets/websockets_impl.py b/uvicorn/protocols/websockets/websockets_impl.py
--- a/uvicorn/protocols/websockets/websockets_impl.py
+++ b/uvicorn/protocols/websockets/websockets_impl.py
@@ -227,7 +227,7 @@ async def asgi_send(self, message):
                 self.logger.info(
                     '%s - "WebSocket %s" [accepted]',
                     self.scope["client"],
-                    self.scope["root_path"] + self.scope["path"],
+                    self.scope["path"],
                 )
                 self.initial_response = None
                 self.accepted_subprotocol = message.get("subprotocol")
@@ -237,7 +237,7 @@ async def asgi_send(self, message):
                 self.logger.info(
                     '%s - "WebSocket %s" 403',
                     self.scope["client"],
-                    self.scope["root_path"] + self.scope["path"],
+                    self.scope["path"],
                 )
                 self.initial_response = (http.HTTPStatus.FORBIDDEN, [], b"")
                 self.handshake_started_event.set()
diff --git a/uvicorn/protocols/websockets/wsproto_impl.py b/uvicorn/protocols/websockets/wsproto_impl.py
--- a/uvicorn/protocols/websockets/wsproto_impl.py
+++ b/uvicorn/protocols/websockets/wsproto_impl.py
@@ -253,7 +253,7 @@ async def send(self, message):
                 self.logger.info(
                     '%s - "WebSocket %s" [accepted]',
                     self.scope["client"],
-                    self.scope["root_path"] + self.scope["path"],
+                    self.scope["path"],
                 )
                 self.handshake_complete = True
                 subprotocol = message.get("subprotocol")
@@ -269,7 +269,7 @@ async def send(self, message):
                 self.logger.info(
                     '%s - "WebSocket %s" 403',
                     self.scope["client"],
-                    self.scope["root_path"] + self.scope["path"],
+                    self.scope["path"],
                 )
                 self.handshake_complete = True
                 self.close_sent = True


Test patch: