about summary refs log tree commit diff stats
path: root/internal/server/headers.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-02 23:18:19 +0200
committerAlan Pearce2024-05-02 23:20:30 +0200
commit73603079e29bc89c54296a9e12b5a779cd84c023 (patch)
tree3e5d0c0c87b81a007667fc4b533cb9403675a422 /internal/server/headers.go
parent7ad48953a4d9470d2f4fe89343c0b09bff410c58 (diff)
downloadsearchix-73603079e29bc89c54296a9e12b5a779cd84c023.tar.lz
searchix-73603079e29bc89c54296a9e12b5a779cd84c023.tar.zst
searchix-73603079e29bc89c54296a9e12b5a779cd84c023.zip
feat: serve a very basic html template
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)
+	})
+}