scope = {
"type": "websocket",
"path": unquote(path),
+ "raw_path": path.encode(),
"root_path": self.root_path,
"scheme": scheme,
"query_string": query.encode(),
"http_version": "1.1",
"method": request.method,
"path": unquote(path),
+ "raw_path": path.encode(),
"root_path": self.root_path,
"scheme": scheme,
"query_string": query.encode(),
import pytest
from starlette.requests import ClientDisconnect, Request, State
-from starlette.responses import JSONResponse, Response
+from starlette.responses import JSONResponse, PlainTextResponse, Response
def test_request_url(test_client_factory):
assert len(request) == 3
+def test_request_raw_path(test_client_factory):
+ async def app(scope, receive, send):
+ request = Request(scope, receive)
+ path = request.scope["path"]
+ raw_path = request.scope["raw_path"]
+ response = PlainTextResponse(f"{path}, {raw_path}")
+ await response(scope, receive, send)
+
+ client = test_client_factory(app)
+ response = client.get("/he%2Fllo")
+ assert response.text == "/he/llo, b'/he%2Fllo'"
+
+
def test_request_without_setting_receive(test_client_factory):
"""
If Request is instantiated without the receive channel, then .body()