Skip to content

Commit 23f9f96

Browse files
committed
golink: set Strict-Transport-Security header on HTTPS responses
Signed-off-by: Patrick O'Doherty <[email protected]>
1 parent 2fc65c3 commit 23f9f96

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

golink.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func Run() error {
217217
}
218218
s := http.Server{
219219
Addr: ":443",
220-
Handler: serveHandler(),
220+
Handler: HSTS(serveHandler()),
221221
TLSConfig: &tls.Config{
222222
GetCertificate: localClient.GetCertificate,
223223
},
@@ -357,6 +357,15 @@ func redirectHandler(hostname string) http.Handler {
357357
})
358358
}
359359

360+
// HSTS wraps the provided handler and sets Strict-Transport-Security header on
361+
// all responses.
362+
func HSTS(h http.Handler) http.Handler {
363+
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
364+
w.Header().Set("Strict-Transport-Security", "max-age=31536000")
365+
h.ServeHTTP(w, r)
366+
})
367+
}
368+
360369
// serverHandler returns the main http.Handler for serving all requests.
361370
func serveHandler() http.Handler {
362371
mux := http.NewServeMux()

0 commit comments

Comments
 (0)