Add 100-continue test (#68)

This commit is contained in:
Tom Christie 2019-05-16 10:21:24 +01:00 committed by GitHub
parent 144ce4f7c3
commit 4fe6bc058a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View 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

View 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()