2023-05-11 20:42:30 +00:00
|
|
|
package coderd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2023-05-22 18:02:39 +00:00
|
|
|
// LatencyCheck is an endpoint for the web ui to measure latency with.
|
|
|
|
// allowAll allows any Origin to get timing information. The allowAll should
|
|
|
|
// only be set in dev modes.
|
|
|
|
//
|
|
|
|
//nolint:revive
|
2023-06-06 15:26:13 +00:00
|
|
|
func LatencyCheck() http.HandlerFunc {
|
2023-05-11 20:42:30 +00:00
|
|
|
return func(rw http.ResponseWriter, r *http.Request) {
|
|
|
|
// Allowing timing information to be shared. This allows the browser
|
|
|
|
// to exclude TLS handshake timing.
|
2023-06-06 15:26:13 +00:00
|
|
|
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", "*")
|
2023-05-11 20:42:30 +00:00
|
|
|
rw.WriteHeader(http.StatusOK)
|
2023-06-06 15:26:13 +00:00
|
|
|
_, _ = rw.Write([]byte("OK"))
|
2023-05-11 20:42:30 +00:00
|
|
|
}
|
|
|
|
}
|