Last active
August 13, 2024 20:47
-
-
Save scottzach1/a635c4b7c485842cf0f0621be857a7bd to your computer and use it in GitHub Desktop.
A quick Flask app that logs everything to disk.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A quick Flask app that dumps everything to disk. | |
!!THIS IS NOT SAFE FOR PRODUCTION CODE!! | |
""" | |
from pathlib import Path | |
from flask import Flask, request, jsonify | |
import json | |
import time | |
app = Flask(__name__) | |
EXPORT_DIR = Path("requests/flask") | |
EXPORT_DIR.mkdir(exist_ok=True, parents=True) | |
@app.route("/", defaults={"path": ""}) | |
@app.route("/<path:path>", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"]) | |
def catch_all(path): | |
# Gather request information | |
request_info = { | |
"timestamp": datetime.now().isoformat(), | |
"method": request.method, | |
"url": request.url, | |
"path": path, | |
"headers": dict(request.headers), | |
"args": request.args.to_dict(), | |
"form": request.form.to_dict(), | |
"json": request.get_json(silent=True), | |
"data": request.data.decode("utf-8"), | |
"remote_addr": request.remote_addr, | |
} | |
with open(EXPORT_DIR / f'{time.time()}.json', "w") as f: | |
json.dump(request_info, f, indent=2) | |
return jsonify({"status": "success", "filename": str(filename)}), 200 | |
if __name__ == "__main__": | |
app.run(debug=True, host="0.0.0.0", port=6666) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment