This is a Python web proxy server that provides caching functionality, time-based access control, and also works as an HTTP server for serving static files. The proxy server allows clients to access web resources through it, and it caches the responses from web servers to improve response time for subsequent requests. Additionally, the proxy server can limit access based on specified time ranges and serve static files when appropriate.
- Python 3.x
config.inifile with cache time, whitelist URLs, and time restriction settings
-
Clone the repository or download the
proxy.pyscript andconfig.inifile to your machine. -
Ensure you have Python 3.x installed.
-
Modify the
config.inifile to set the cache time, whitelist URLs, and time restriction settings according to your requirements.
The config.ini file contains the following parameters:
cache_time: The time, in seconds, to cache responses from web servers. (e.g.,cache_time = 900for 15 minutes)whitelisting: Comma-separated list of URLs that are allowed to access through the proxy.time: The time range during which access is allowed (format:HH-HH, e.g.,8-20for 8 AM to 8 PM).timeout: The timeout value in seconds for connections to web servers.enabling_whitelist: A boolean flag to enable or disable URL whitelisting (set toTrueto enable).time_restriction: A boolean flag to enable or disable time-based access control (set toTrueto enable).
Run the proxy server by executing the following command:
python proxy.py <HOST> <PORT>Replace <HOST> and <PORT> with the desired host and port number on which you want the proxy server to listen for incoming connections.
- The proxy server caches responses from web servers for a configurable duration (
cache_timeinconfig.ini). Subsequent requests for the same resource within the cache duration will be served from the cache, reducing response time and improving performance.
- The proxy server can restrict access to specific time ranges (
timeinconfig.ini). Only requests received during the specified time range will be allowed, and requests outside this range will receive a "403 Forbidden" response.
- Optionally, the proxy server can enforce URL whitelisting (
whitelistinginconfig.ini). If enabled (enabling_whitelist = Trueinconfig.ini), only requests to URLs listed in the whitelist will be allowed, and requests to other URLs will receive a "403 Forbidden" response.
The proxy server can work as an HTTP server with the following additional features:
To save a message in a server text file, use the following curl command:
curl -X POST -d "HELLO WORLD" <url>/submitTo upload a file and save it under a specified file name, use the following curl command:
curl -H "File-Name: <file name>" --data-binary @<file path> <url>To download an uploaded file, use the following curl command:
curl <url>/<uploaded file name>Alternatively, you can open your browser and go to <url>/<uploaded file name> to download the file.
- Start the proxy server by running:
python proxy.py 127.0.0.1 8888-
Set your web browser or application to use the proxy server at
127.0.0.1:8888. -
Access web resources as usual through your browser or application. The proxy server will handle caching, access control, and also serve static files with the additional features described above.
-
Modify the
config.inifile to customize cache time, whitelist URLs, and time restrictions according to your needs.
- The proxy server supports
GET,HEAD,POST, and additional features such asSUBMITandUPLOAD. Unsupported methods will receive a "403 Forbidden" response. - The proxy server will close the connection after each request-response cycle.