about summary refs log tree commit diff stats
path: root/internal/server/headers.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/server/headers.go')
-rw-r--r--internal/server/headers.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/internal/server/headers.go b/internal/server/headers.go
new file mode 100644
index 0000000..0efc384
--- /dev/null
+++ b/internal/server/headers.go
@@ -0,0 +1,17 @@
+package server
+
+import (
+	"net/http"
+	cfg "searchix/internal/config"
+)
+
+func AddHeadersMiddleware(next http.Handler, config *cfg.Config) http.Handler {
+	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		for h, v := range config.Headers {
+			w.Header().Add(h, v)
+		}
+		w.Header().Add("Content-Security-Policy", config.CSP.String())
+
+		next.ServeHTTP(w, r)
+	})
+}