File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change 35
35
authTokenMutexes map [string ]* sync.Mutex = make (map [string ]* sync.Mutex )
36
36
colCounters map [string ]* utils.Counter = make (map [string ]* utils.Counter )
37
37
logger log.Logger = * utils .SpectrumLogger ()
38
+ https bool = true
38
39
)
39
40
40
41
type handler struct {
@@ -89,6 +90,7 @@ func main() {
89
90
if cfg .TlsServerConfig .CaCert != "" && cfg .TlsServerConfig .ServerCert != "" && cfg .TlsServerConfig .ServerKey != "" {
90
91
startHTTPS (CSRF (r ))
91
92
} else {
93
+ https = false
92
94
startHTTP (CSRF (r ))
93
95
}
94
96
}
@@ -151,6 +153,9 @@ func startHTTPS(handler http.Handler) {
151
153
152
154
func rootFunc (w http.ResponseWriter , r * http.Request ) {
153
155
if r .Method == "GET" {
156
+ if https {
157
+ w .Header ().Add ("Strict-Transport-Security" , "max-age=31536000; includeSubDomains; preload" )
158
+ }
154
159
_ , _ = w .Write ([]byte (`<html>
155
160
<head><title>Spectrum Virtualize exporter</title></head>
156
161
<body>
@@ -215,6 +220,9 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
215
220
_ , _ = w .Write ([]byte (fmt .Sprintf ("Couldn't create handler: %s" , err .Error ())))
216
221
return
217
222
}
223
+ if https {
224
+ w .Header ().Add ("Strict-Transport-Security" , "max-age=31536000; includeSubDomains; preload" )
225
+ }
218
226
handler .ServeHTTP (w , r )
219
227
} else {
220
228
http .Error (w , "403 Forbidden" , http .StatusForbidden )
You can’t perform that action at this time.
0 commit comments