from aiohttp import web
import zlib
async def index(request):
return web.Response(text=await request.text())
app = web.Application()
app.router.add_post('/', index)
web.run_app(app, host='127.0.0.1', port=8080)
import aiohttp
import asyncio
import gzip
async def fetch(client):
data = gzip.compress('Hello'.encode())
async with client.post('http://localhost:8080/', data=data, headers={'Content-Encoding': 'gzip'}) as resp:
assert resp.status == 200
return await resp.text()
async def main(loop):
async with aiohttp.ClientSession(loop=loop) as client:
html = await fetch(client)
print(html)
loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))