assert scope["type"] == "http"
if scope["path"] == "/slow_response":
await slow_response(scope, receive, send)
+ elif scope["path"].startswith("/status"):
+ await status_code(scope, receive, send)
else:
await hello_world(scope, receive, send)
await send({"type": "http.response.body", "body": b"Hello, world!"})
+async def status_code(scope, receive, send):
+ status_code = int(scope["path"].replace("/status/", ""))
+ await send(
+ {
+ "type": "http.response.start",
+ "status": status_code,
+ "headers": [[b"content-type", b"text/plain"]],
+ }
+ )
+ await send({"type": "http.response.body", "body": b"Hello, world!"})
+
+
@pytest.fixture
async def server():
config = Config(app=app, lifespan="off")