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.ini
file with cache time, whitelist URLs, and time restriction settings
-
Clone the repository or download the
proxy.py
script andconfig.ini
file to your machine. -
Ensure you have Python 3.x installed.
-
Modify the
config.ini
file 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 = 900
for 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-20
for 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 toTrue
to enable).time_restriction
: A boolean flag to enable or disable time-based access control (set toTrue
to 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_time
inconfig.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 (
time
inconfig.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 (
whitelisting
inconfig.ini
). If enabled (enabling_whitelist = True
inconfig.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>/submit
To 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.ini
file to customize cache time, whitelist URLs, and time restrictions according to your needs.
- The proxy server supports
GET
,HEAD
,POST
, and additional features such asSUBMIT
andUPLOAD
. Unsupported methods will receive a "403 Forbidden" response. - The proxy server will close the connection after each request-response cycle.