mirror of
https://github.com/ZizzyDizzyMC/linx-server.git
synced 2026-01-23 02:14:33 +00:00
Add ability to set arbitrary headers
This is useful if you want to add headers for things like HTTP Strict Transport Security or HTTP Public Key Pinning.
This commit is contained in:
parent
1f3bc4bfea
commit
39bb999db6
3 changed files with 61 additions and 0 deletions
27
headers.go
Normal file
27
headers.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type addheaders struct {
|
||||
h http.Handler
|
||||
headers []string
|
||||
}
|
||||
|
||||
func (a addheaders) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
for _, header := range a.headers {
|
||||
headerSplit := strings.SplitN(header, ": ", 2)
|
||||
w.Header().Add(headerSplit[0], headerSplit[1])
|
||||
}
|
||||
|
||||
a.h.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func AddHeaders(headers []string) func(http.Handler) http.Handler {
|
||||
fn := func(h http.Handler) http.Handler {
|
||||
return addheaders{h, headers}
|
||||
}
|
||||
return fn
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue