]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Add `status_code` endpoint
authorMatus Ferech <matus.ferech@telekom.com>
Sat, 4 May 2019 15:44:06 +0000 (17:44 +0200)
committerMatus Ferech <matus.ferech@telekom.com>
Sat, 4 May 2019 15:44:06 +0000 (17:44 +0200)
tests/conftest.py

index 3ceaeec0419969f76891a82ac941cf9678fd15b9..aab371cf2c2ddf373df1d756d213b20bb061b0a8 100644 (file)
@@ -9,6 +9,8 @@ async def app(scope, receive, send):
     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)
 
@@ -36,6 +38,18 @@ async def slow_response(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")