From 4fe6bc058aaef044b875320a0ad0ccf3576de775 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 16 May 2019 10:21:24 +0100 Subject: [PATCH] Add 100-continue test (#68) --- tests/client/test_async_client.py | 13 +++++++++++++ tests/conftest.py | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/tests/client/test_async_client.py b/tests/client/test_async_client.py index 27602d12..a1156545 100644 --- a/tests/client/test_async_client.py +++ b/tests/client/test_async_client.py @@ -111,3 +111,16 @@ async def test_delete(server): response = await client.delete(url) assert response.status_code == 200 assert response.text == "Hello, world!" + + +@pytest.mark.asyncio +async def test_100_continue(server): + url = "http://127.0.0.1:8000/echo_body" + headers = {"Expect": "100-continue"} + data = b"Echo request body" + + async with httpcore.AsyncClient() as client: + response = await client.post(url, headers=headers, data=data) + + assert response.status_code == 200 + assert response.content == data diff --git a/tests/conftest.py b/tests/conftest.py index 32e7ddd5..3eff9888 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -12,6 +12,8 @@ async def app(scope, receive, send): await slow_response(scope, receive, send) elif scope["path"].startswith("/status"): await status_code(scope, receive, send) + elif scope["path"].startswith("/echo_body"): + await echo_body(scope, receive, send) else: await hello_world(scope, receive, send) @@ -51,6 +53,25 @@ async def status_code(scope, receive, send): await send({"type": "http.response.body", "body": b"Hello, world!"}) +async def echo_body(scope, receive, send): + body = b'' + more_body = True + + while more_body: + message = await receive() + body += message.get('body', b'') + more_body = message.get('more_body', False) + + await send( + { + "type": "http.response.start", + "status": 200, + "headers": [[b"content-type", b"text/plain"]], + } + ) + await send({"type": "http.response.body", "body": body}) + + @pytest.fixture def cert_and_key_paths(): ca = trustme.CA() -- 2.47.3