all repos — searchix @ a597c5df0f9f19058b2c83fde7e7777e1d762581

Search engine for NixOS, nix-darwin, home-manager and NUR users

internal/server/headers.go (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package server

import (
	"net/http"

	cfg "go.alanpearce.eu/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.Web.Headers {
			w.Header().Add(h, v)
		}
		w.Header().Add("Content-Security-Policy", config.Web.ContentSecurityPolicy.String())
		w.Header().Add("Server", "go.alanpearce.eu/searchix/"+cfg.Version)

		next.ServeHTTP(w, r)
	})
}