]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Add 100-continue test (#68)
authorTom Christie <tom@tomchristie.com>
Thu, 16 May 2019 09:21:24 +0000 (10:21 +0100)
committerGitHub <noreply@github.com>
Thu, 16 May 2019 09:21:24 +0000 (10:21 +0100)
tests/client/test_async_client.py
tests/conftest.py

index 27602d12d6455091b4518619561224c117b3063f..a1156545949486efd9532f777541646598a5473a 100644 (file)
@@ -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
index 32e7ddd5033243604962a973bdc646fb8cba4623..3eff9888f25a164cecb114f383f2c3a0a148d961 100644 (file)
@@ -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()