mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: add prometheus timing to latency endpoint (#7742)
* chore: Prometheus timing to latency endpoint
This commit is contained in:
+8
-15
@@ -2,8 +2,6 @@ package coderd
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// LatencyCheck is an endpoint for the web ui to measure latency with.
|
||||
@@ -11,22 +9,17 @@ import (
|
||||
// only be set in dev modes.
|
||||
//
|
||||
//nolint:revive
|
||||
func LatencyCheck(allowAll bool, allowedOrigins ...*url.URL) http.HandlerFunc {
|
||||
allowed := make([]string, 0, len(allowedOrigins))
|
||||
for _, origin := range allowedOrigins {
|
||||
// Allow the origin without a path
|
||||
tmp := *origin
|
||||
tmp.Path = ""
|
||||
allowed = append(allowed, strings.TrimSuffix(origin.String(), "/"))
|
||||
}
|
||||
if allowAll {
|
||||
allowed = append(allowed, "*")
|
||||
}
|
||||
origins := strings.Join(allowed, ",")
|
||||
func LatencyCheck() http.HandlerFunc {
|
||||
return func(rw http.ResponseWriter, r *http.Request) {
|
||||
// Allowing timing information to be shared. This allows the browser
|
||||
// to exclude TLS handshake timing.
|
||||
rw.Header().Set("Timing-Allow-Origin", origins)
|
||||
rw.Header().Set("Timing-Allow-Origin", "*")
|
||||
// Always allow all CORs on this route.
|
||||
rw.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
rw.Header().Set("Access-Control-Allow-Headers", "*")
|
||||
rw.Header().Set("Access-Control-Allow-Credentials", "false")
|
||||
rw.Header().Set("Access-Control-Allow-Methods", "*")
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
_, _ = rw.Write([]byte("OK"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user