You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
874 B
34 lines
874 B
4 years ago
|
import asyncio
|
||
|
import aiohttp
|
||
|
|
||
|
|
||
|
async def get_root(client):
|
||
|
async with client.get('http://localhost/') as resp:
|
||
|
assert resp.status == 200
|
||
|
return await resp.json()
|
||
|
|
||
|
|
||
|
async def main():
|
||
|
unix_conn = aiohttp.UnixConnector(path='./input.sock')
|
||
|
|
||
|
try:
|
||
|
async with aiohttp.ClientSession(connector=unix_conn) as client:
|
||
|
print('---------------------------')
|
||
|
print('Request GET "/" HTTP/1.1:')
|
||
|
response = await get_root(client)
|
||
|
print(f'Response: {response}')
|
||
|
print('---------------------------')
|
||
|
except KeyboardInterrupt:
|
||
|
raise
|
||
|
finally:
|
||
|
print('\nClosing connection...')
|
||
|
await unix_conn.close()
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
loop = asyncio.new_event_loop()
|
||
|
try:
|
||
|
loop.run_until_complete(main())
|
||
|
except KeyboardInterrupt:
|
||
|
loop.close()
|