Add 100-continue test (#68)
This commit is contained in:
parent
144ce4f7c3
commit
4fe6bc058a
@ -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
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user