forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlatencycheck.go
More file actions
25 lines (23 loc) · 824 Bytes
/
latencycheck.go
File metadata and controls
25 lines (23 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package coderd
import (
"net/http"
)
// 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
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", "*")
// 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"))
}
}