From: Matus Ferech Date: Sat, 4 May 2019 15:44:06 +0000 (+0200) Subject: Add `status_code` endpoint X-Git-Tag: 0.3.0~41^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0629e55f98dd315bcc31ec894b523f424afe3125;p=thirdparty%2Fhttpx.git Add `status_code` endpoint --- diff --git a/tests/conftest.py b/tests/conftest.py index 3ceaeec0..aab371cf 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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")