This project is a simple proxy server built using Django that can handle various HTTP methods (GET, POST, PUT, DELETE) and forward requests to a user-specified target URL. The proxy server accepts headers, text data, and JSON data from the client, forwards them to the target server, and returns the response.
- Proxy requests to a dynamic target URL passed as a query parameter.
- Supports various HTTP methods: GET, POST, PUT, DELETE.
- Handles headers, query parameters, and request bodies (text, JSON).
- Returns the response from the target server with appropriate headers and status codes.
- Error handling for 4xx and 5xx server errors, as well as network issues.
docker run -it --rm proxy
# OR
docker-compose up -d --build
# To stop and remove the containers
docker-compose downsource venv/bin/activate && export $(cat .env | xargs)
python manage.py runserver 0.0.0.0:8000curl -X GET "http://127.0.0.1:8000/proxy/?target_url=https://api.example.com/data"This forwards the GET request to https://api.example.com/data and returns the response.
curl -X POST "http://127.0.0.1:8000/proxy/?target_url=https://api.example.com/data" \
-H "Content-Type: application/json" \
-d '{"key": "value"}'This forwards the POST request with the JSON body to the target URL.
curl -X PUT "http://127.0.0.1:8000/proxy/?target_url=https://api.example.com/data" \
-H "Content-Type: application/json" \
-d '{"key": "new_value"}'This forwards the PUT request to the target URL along with the provided data.
curl -X DELETE "http://127.0.0.1:8000/proxy/?target_url=https://api.example.com/resource/123"This forwards the DELETE request to delete the resource at the target URL.
python -m venv venv
source venv/bin/activatepip install --upgrade django requests pre-commit gunicorn whitenoiseOR
pip install -r requirements.txtif change in packages then update the requirements with below cmd
pip freeze > requirements.txt
pre-commit installEnsure that your docker-compose.yml is correctly set up to handle the Django environment. Start by bringing up the Docker containers:
docker-compose up -d --buildMake sure that Dockerfile and docker-compose.yml have the proper configurations for the Django project.
OR
When using a virtual environment:
cp .env.template .env
export $(cat .env | xargs)This will load environment variables from the .env file.
Run the following commands to apply the database migrations:
python manage.py makemigrations
python manage.py migrateYou can create a superuser for the Django admin by running:
python manage.py createsuperuser --username admin --email admin@example.comStart the Django development server:
python manage.py runserver 0.0.0.0:8000When using Docker, this will be mapped to your local machine's port 8000, making the project accessible via
http://localhost:8000.
The project includes a comprehensive set of test cases for the proxy server.
To run the tests, use the following command:
python manage.py testThis project is licensed under the MIT License.