Skip to main content

Re-route aiohttp session requests. Usefull for testing.

Project description

aiohttp-hijacks

Hijack aiohttp session to re-route the requests.

from aiohttp_hijacks import FakeServer, FakeSession, route


class Server(FakeServer):
    """ Application that will respond to the client. """
    @route('/')
    async def get_abc(self, request):
        self.calls += 1
        return self.json_response({"status": "ok"})


# Reroute google.com → 127.0.0.1
async with Server() as server:  # instantiate Server handling '127.0.0.1:{server.port}/abc'
    async with FakeSession(reroute={'google.com': server.port}) as session:
        # redirecting calls to http(s)://google.com to 127.0.0.1:{server.port}
        resp = await session.get("https://google.com")
        data = await resp.json()
        assert data == {"status": "ok"}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp-hijacks-0.0.1.tar.gz (22.0 kB view hashes)

Uploaded Source

Built Distribution

aiohttp_hijacks-0.0.1-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page