mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/httpserver: call Request.Header() only once instead of calling it each time a new request header is set
This is a follow-up for ad839aa492
This commit is contained in:
parent
68f82b1c06
commit
efb6ac27c2
1 changed files with 9 additions and 8 deletions
|
@ -242,20 +242,21 @@ func handlerWrapper(s *server, w http.ResponseWriter, r *http.Request, rh Reques
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
h := w.Header()
|
||||||
if *headerHSTS != "" {
|
if *headerHSTS != "" {
|
||||||
w.Header().Add("Strict-Transport-Security", *headerHSTS)
|
h.Add("Strict-Transport-Security", *headerHSTS)
|
||||||
}
|
}
|
||||||
if *headerFrameOptions != "" {
|
if *headerFrameOptions != "" {
|
||||||
w.Header().Add("X-Frame-Options", *headerFrameOptions)
|
h.Add("X-Frame-Options", *headerFrameOptions)
|
||||||
}
|
}
|
||||||
if *headerCSP != "" {
|
if *headerCSP != "" {
|
||||||
w.Header().Add("Content-Security-Policy", *headerCSP)
|
h.Add("Content-Security-Policy", *headerCSP)
|
||||||
}
|
}
|
||||||
w.Header().Add("X-Server-Hostname", hostname)
|
h.Add("X-Server-Hostname", hostname)
|
||||||
requestsTotal.Inc()
|
requestsTotal.Inc()
|
||||||
if whetherToCloseConn(r) {
|
if whetherToCloseConn(r) {
|
||||||
connTimeoutClosedConns.Inc()
|
connTimeoutClosedConns.Inc()
|
||||||
w.Header().Set("Connection", "close")
|
h.Set("Connection", "close")
|
||||||
}
|
}
|
||||||
path := r.URL.Path
|
path := r.URL.Path
|
||||||
prefix := GetPathPrefix()
|
prefix := GetPathPrefix()
|
||||||
|
@ -280,7 +281,7 @@ func handlerWrapper(s *server, w http.ResponseWriter, r *http.Request, rh Reques
|
||||||
}
|
}
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/health":
|
case "/health":
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
h.Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
deadline := atomic.LoadInt64(&s.shutdownDelayDeadline)
|
deadline := atomic.LoadInt64(&s.shutdownDelayDeadline)
|
||||||
if deadline <= 0 {
|
if deadline <= 0 {
|
||||||
w.Write([]byte("OK"))
|
w.Write([]byte("OK"))
|
||||||
|
@ -315,7 +316,7 @@ func handlerWrapper(s *server, w http.ResponseWriter, r *http.Request, rh Reques
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
h.Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
appmetrics.WritePrometheusMetrics(w)
|
appmetrics.WritePrometheusMetrics(w)
|
||||||
metricsHandlerDuration.UpdateDuration(startTime)
|
metricsHandlerDuration.UpdateDuration(startTime)
|
||||||
return
|
return
|
||||||
|
@ -323,7 +324,7 @@ func handlerWrapper(s *server, w http.ResponseWriter, r *http.Request, rh Reques
|
||||||
if !CheckAuthFlag(w, r, *flagsAuthKey, "flagsAuthKey") {
|
if !CheckAuthFlag(w, r, *flagsAuthKey, "flagsAuthKey") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
h.Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
flagutil.WriteFlags(w)
|
flagutil.WriteFlags(w)
|
||||||
return
|
return
|
||||||
case "/-/healthy":
|
case "/-/healthy":
|
||||||
|
|
Loading…
Reference in a new issue