patx/micropie
added example to manually set security headers for production enviorments
Commit 81d5156 · patx · 01/23/2025 at 8:49PM
Comments
No comments yet.
Diff
diff --git a/MicroPie.py b/MicroPie.py
index 21b92bb..25bf93f 100644
--- a/MicroPie.py
+++ b/MicroPie.py
@@ -528,5 +528,5 @@ class Server:
except:
# We may get "headers already set" here, but let's log and ignore
pass
- return [f"500 Internal Server Error: {str(e)}".encode("utf-8")]
+ return ["500 Internal Server Error:"]
diff --git a/examples/headers/app.py b/examples/headers/app.py
new file mode 100644
index 0000000..1d1f9d2
--- /dev/null
+++ b/examples/headers/app.py
@@ -0,0 +1,16 @@
+from MicroPie import Server
+
+class Root(Server):
+ def index(self):
+ headers = [
+ ("Content-Type", "text/html"),
+ ("X-Content-Type-Options", "nosniff"),
+ ("X-Frame-Options", "DENY"),
+ ("X-XSS-Protection", "1; mode=block"),
+ ("Strict-Transport-Security", "max-age=31536000; includeSubDomains"),
+ ("Content-Security-Policy", "default-src 'self'")
+ ]
+ return 200, "hello world", headers
+
+app = Root()
+wsgi_app = app.wsgi_app