-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_server.py
More file actions
39 lines (31 loc) · 1.18 KB
/
Copy pathtest_server.py
File metadata and controls
39 lines (31 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, request, send_from_directory, abort
import os
app = Flask(__name__)
# Configure writable directories
UPLOAD_DIRS = {
'uploads': {'confirm': True}, # Normal behavior (PUT+GET)
'files': {'confirm': True}, # Normal behavior
'webapps': {'confirm': False} # Manual review case (PUT succeeds, GET fails)
}
# Create directories
for dir_name in UPLOAD_DIRS:
os.makedirs(dir_name, exist_ok=True)
@app.route('/<path:directory>/<path:filename>', methods=['PUT', 'GET'])
def handle_file(directory, filename):
# Check if directory is configured
if directory not in UPLOAD_DIRS:
abort(404)
file_path = os.path.join(directory, filename)
if request.method == 'PUT':
with open(file_path, 'wb') as f:
f.write(request.data)
return '', 201
elif request.method == 'GET':
# Force manual review for webapps directory
if not UPLOAD_DIRS[directory]['confirm']:
abort(404) # Intentionally fail GET
if os.path.exists(file_path):
return send_from_directory(directory, filename)
abort(404)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)