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.
Todo
- Processing responses before saving
- Optionally record requests
- TUI for viewing requests and responses
- Hosting multiple reloading proxies on separate ports from a single parent
- Content-adressed response content deduplication
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file fauxy-0.0.2.tar.gz
.
File metadata
- Download URL: fauxy-0.0.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.11 Darwin/22.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26f8fbbe3931d81956fbbf92c33b7d68648b1c823cb0044f8588340d35caa090 |
|
MD5 | 2fe1c910b2bbee1f3d6b77633cc34c8f |
|
BLAKE2b-256 | f973ec7ae8012ffa60bb5fae38e07a3536a5a9bc4a164da9d6e46f8ad039d024 |
File details
Details for the file fauxy-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: fauxy-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee9c711dc342ab7facdc5db99d1c5d76477a1456fce07b263c329708b661bf42 |
|
MD5 | d3446418c790bd183fb520108560093c |
|
BLAKE2b-256 | 09646afeab12c0f38293ca174f7f491176c4a9f44ca816fc0c3b98b1e3e40457 |