Skip to content
This repository was archived by the owner on Oct 14, 2025. It is now read-only.

Commit 749bb11

Browse files
feat: flask app for local debugging (#30)
1 parent 749ef34 commit 749bb11

5 files changed

Lines changed: 133 additions & 1 deletion

File tree

.gitignore

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,18 @@ release_notes.md
8686

8787
# Development files
8888

89-
dev/
89+
dev/
90+
91+
# Python
92+
*.pyc
93+
__pycache__/
94+
*.pyo
95+
*.pyd
96+
*.pdb
97+
*.egg-info/
98+
*.egg
99+
*.whl
100+
*.py[cod]
101+
.venv/
102+
*.env
103+
*.venv/

tests/flask-options-app/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.9-slim
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt requirements.txt
6+
RUN pip install --no-cache-dir -r requirements.txt
7+
8+
COPY app.py app.py
9+
10+
EXPOSE 5000
11+
12+
CMD ["python", "app.py"]

tests/flask-options-app/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
### Flask Options App
2+
3+
This is a simple Flask application that demonstrates how to handle HTTP OPTIONS requests.
4+
It is designed to be run inside a Docker container and can be used for testing purposes.
5+
The app is configured to run on port 5000 inside the container and can be accessed on port 8081 on your localhost.
6+
7+
- [Flask Options App](#flask-options-app)
8+
- [Testing the App](#testing-the-app)
9+
- [Accessing the App](#accessing-the-app)
10+
- [Stopping the App](#stopping-the-app)
11+
- [Testing HTTP OPTIONS Requests](#testing-http-options-requests)
12+
13+
### Testing the App
14+
15+
Navigate to the flask-options-app directory and execute the following commands:
16+
17+
```bash
18+
docker build -t flask-options-app .
19+
docker run --rm -it -p 8081:5000 flask-options-app
20+
21+
# If you want to run a shell inside the container for debugging:
22+
docker run -it -p 8081:5000 --entrypoint /bin/sh flask-options-app
23+
24+
# If you want to run the app in the background:
25+
docker run -d -p 8081:5000 flask-options-app
26+
```
27+
28+
This will build the Docker image and run the container, mapping port 5000 inside the container to port 8081 on your localhost.
29+
30+
### Accessing the App
31+
32+
Once the container is running, you can access the Flask app by navigating to [`http://localhost:8081/api/test`](http://localhost:8081/api/test) in your web browser.
33+
You should see the Flask app running and be able to interact with it.
34+
35+
### Stopping the App
36+
37+
To stop the app, you can either stop the container from your terminal or use `docker-compose down` if you are using Docker Compose.
38+
39+
### Testing HTTP OPTIONS Requests
40+
41+
You can test the app by sending a GET request to the `/api/test` endpoint. You can use tools like `curl`, Postman, or your web browser to do this.
42+
43+
```bash
44+
curl -X GET http://localhost:8081/api/test \
45+
-x http://127.0.0.1:9090 \
46+
-k -v
47+
```
48+
49+
```bash
50+
curl -X OPTIONS http://localhost:8081/api/test \
51+
-x http://127.0.0.1:9090 \
52+
-k -v
53+
```
54+
55+
To find the traffic in Caido, you can use the following HTTQL query :
56+
57+
```sql
58+
request.url == "http://localhost:8081/api/test"
59+
```
60+
61+
Or:
62+
63+
```sql
64+
request.url == "http://localhost:8081/api/test" and request.method == "OPTIONS"
65+
```
66+
67+
Or:
68+
69+
```sql
70+
request.url.path == "/api/test"
71+
```

tests/flask-options-app/app.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from flask import Flask, jsonify, make_response, request
2+
3+
app = Flask(__name__)
4+
5+
6+
@app.route("/api/test", methods=["GET", "POST", "OPTIONS"])
7+
def test_endpoint():
8+
if request.method == "OPTIONS":
9+
response = make_response()
10+
response.headers["Access-Control-Allow-Origin"] = "*"
11+
response.headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS"
12+
response.headers["Access-Control-Allow-Headers"] = "Content-Type"
13+
return response
14+
elif request.method == "GET":
15+
return jsonify({"message": "GET request received"})
16+
elif request.method == "POST":
17+
data = request.get_json()
18+
return jsonify({"message": "POST request received", "data": data})
19+
20+
21+
# Add both Allow and Access-Control-Allow-Methods headers to all responses
22+
@app.after_request
23+
def add_allow_headers(response):
24+
# Add standard Allow header (for non-CORS clients)
25+
response.headers["Allow"] = "GET, POST, PUT, DELETE, OPTIONS"
26+
return response
27+
28+
29+
# Add this section to run the server when the script is executed directly
30+
if __name__ == "__main__":
31+
print("Starting Flask test server for MethodCheck on http://localhost:5000")
32+
print("Available endpoint: http://localhost:5000/api/test")
33+
app.run(host="0.0.0.0", port=5000, debug=True)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Flask==2.2.5
2+
Werkzeug==2.2.3

0 commit comments

Comments
 (0)