Skip to content

Instantly share code, notes, and snippets.

@jerzyk
Created June 22, 2018 11:58
Show Gist options
  • Save jerzyk/ea5de8d288a2d5384a17c866265bb829 to your computer and use it in GitHub Desktop.
Save jerzyk/ea5de8d288a2d5384a17c866265bb829 to your computer and use it in GitHub Desktop.
aoi proxy
#!/usr/bin/env python
import aiohttp
import asyncio
from aiojobs.aiohttp import setup, spawn
from aiohttp import web
async def coro(address):
async with aiohttp.ClientSession() as session:
async with session.get(address) as resp:
return await resp.text()
async def index(request):
data = await request.post()
addr = data.get('address')
if addr:
job = await spawn(request, coro(addr))
response = await job.wait()
return web.Response(text=response)
else:
raise web.HTTPBadRequest()
app = web.Application()
app.add_routes([web.post('/', index)])
setup(app)
web.run_app(app)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment