High speed proxy engine to serve light weight content
Env vars can either be loaded from .env
files.
Env Requirements
- proxy_host
str
- Hostname/IP for the proxy server. Defaults tosocket.gethostbyname('localhost')
- proxy_port
int
- Port number for the proxy server. Defaults to8000
- async_proxy
bool
- Enables asynchronous requests to the client. Defaults toFalse
- client_host
str
- Hostname of the client server. Defaults toNone
- client_ip
IPv4Address
- IP address of the client server. Defaults toNone
- client_port
int
- Port number of the client server. Defaults toNone
- client_url
HttpUrl
- Direct URL to the client server. Defaults toNone
- allowed_headers
List[str]
- Headers to allow via CORS. Defaults to*
- allowed_origins
List[str]
- Origins to allow connections through proxy server and CORS. Defaults tohost
- allowed_methods
List[str]
- HTTP methods to allow through proxy server. Defaults to["GET", "POST"]
- rate_limit
Dict/List[Dict]
with the rate limit for the proxy server. Defaults toNone
- remove_headers
List[str]
- Client headers that has to be removed before rendering the response. - add_headers
List[Dict[str, str]]
- Headers to be added before rendering the response.
add_headers
andremove_headers
are executed ONLY after the response is received from the client. This will NOT alter any transaction betweenpyproxy
and the client.
PyProxy may increase an inconspicuous latency to the connections, but due to asynchronous functionality, it is hardly noticeable.
The proxy server is designed to be lightweight and efficient, however streaming large video files may increase the memory usage at server side, due to multi-layered buffering.
While CORS may solve the purpose at the webpage level, the built-in proxy's firewall restricts connections from any origin regardless of the tool used to connect (PostMan, curl, wget etc.)
Due to this behavior, please make sure to specify ALL the origins that are supposed to be allowed (including but not limited to reverse-proxy, CDN, redirect servers etc.)
The built-in proxy service allows you to implement a rate limiter.
Rate limiting allows you to prevent DDoS attacks and maintain server stability and performance.
Docstring format: Google
Styling conventions: PEP 8
and isort
pre-commit
is used to ensure linting.
pre-commit run --all-files
© Vignesh Rao
Licensed under the MIT License