Skip to main content

Faux responses from proxying

Project description

Fauxy is an ASGI webapp that will proxy requests to a remote server. The first time it sees a request, it records the response to disk and returns it. From then on, it can return the recorded response whenever it sees the same request.

Running

Fauxy can be run by any ASGI server. example.py runs fauxy using uvicorn. If you've installed fauxy, you can run it with python example.py.

Matching requests

To decide if a given request matches any recordings, fauxy creates a 'key' for the request. It takes a key_maker function to do this. The key maker function takes in a Starlette Request object and returns a JSON key. Any request that produces identical JSON will be considered a match by fauxy.

Here's a key maker that only matches on the request path:

def path_key(req: Request) -> JSON:
    return {"path": req.url.path}

If fauxy is proxying to example.com, that key maker will say any request to /1/2/3 has the key {"path": "/1/2/3"} The first time fauxy sees it, it'll proxy that to example.com/1/2/3 and record the result. Future requests for /1/2/3 will produce the same key regardless of other attributes of the request e.g. query parameters or HTTP method. Since those keys match, fauxy will return the recording instead of proxying again. If a request is then made for /1/2, it produces different JSON: {"path": "/1/2"}. That means the existing recording won't be found and fauxy will proxy and record it.

Storing responses

Fauxy writes out responses for all requests with a new key to the library directory you pass it. Inside that directory, it creates a directory per recorded response. The response directory is the full request path with a hash of the request key as its final segment.

For our /1/2/3 example, if the library directory is recordings, fauxy could produce the directory recordings/1/2/3/ba8d9c9d. In that example, ba8d9c9d is the hash of the key JSON bytes. When looking for a recording matching a request, fauxy produces the hash, walks the library directory, and returns the first matching hash directory it finds.

While the request path is part of the created directory structure, it doesn't constrain matching. As long as the hash matches, fauxy will return a response. If you include the requested path in the key JSON, the hash will be determined by the path, but if you don't, it won't affect it.

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

fauxy-0.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

fauxy-0.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file fauxy-0.0.1.tar.gz.

File metadata

  • Download URL: fauxy-0.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Darwin/22.4.0

File hashes

Hashes for fauxy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fbeb0fd070bb1505da10884d4224f2d1d151f94b9e484f9cf2aeb658bb5a3f57
MD5 f76c5367ce5034d6376a098aff186889
BLAKE2b-256 decc1366eaec0fdc677c0ee7d9bdc5caa85918cb650377fa966afc1d369732c4

See more details on using hashes here.

File details

Details for the file fauxy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: fauxy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.11 Darwin/22.4.0

File hashes

Hashes for fauxy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cd73bb28aebbb3b840a8f6139f9221f7a4aea980681de29a842fad0bd62211c5
MD5 41e0484d96395d8016f1bf9897a6e272
BLAKE2b-256 8e5549dca82c07f491e303d93e1a2a90fcfc2b8b15ecfef33bfcbd274f430f7a

See more details on using hashes here.

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