2016-12-18 00:25:39 +00:00
|
|
|
import asyncio
|
|
|
|
from sanic import Sanic
|
|
|
|
|
|
|
|
|
|
|
|
def test_bad_request_response():
|
|
|
|
app = Sanic('test_bad_request_response')
|
|
|
|
lines = []
|
2017-02-11 12:34:11 +00:00
|
|
|
@app.after_start
|
2016-12-18 00:25:39 +00:00
|
|
|
async def _request(sanic, loop):
|
|
|
|
connect = asyncio.open_connection('127.0.0.1', 42101)
|
|
|
|
reader, writer = await connect
|
|
|
|
writer.write(b'not http')
|
|
|
|
while True:
|
|
|
|
line = await reader.readline()
|
|
|
|
if not line:
|
|
|
|
break
|
|
|
|
lines.append(line)
|
|
|
|
app.stop()
|
2017-02-11 12:34:11 +00:00
|
|
|
app.run(host='127.0.0.1', port=42101, debug=False)
|
2016-12-18 00:25:39 +00:00
|
|
|
assert lines[0] == b'HTTP/1.1 400 Bad Request\r\n'
|
|
|
|
assert lines[-1] == b'Error: Bad Request'
|