feat: Workspace Proxy picker show latency to each proxy (#7486)

* chore: Add cors to workspace proxies to allow for latency checks
* Add latency check to wsproxy

Use performance API timings.
- Fix cors and timing headers
- Accept custom headers
This commit is contained in:
Steven Masley
2023-05-11 15:42:30 -05:00
committed by GitHub
parent 640fcf450c
commit 8f768f8276
22 changed files with 347 additions and 28 deletions
+24
View File
@@ -0,0 +1,24 @@
package coderd
import (
"net/http"
"net/url"
"strings"
)
func LatencyCheck(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(), "/"))
}
origins := strings.Join(allowed, ",")
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.WriteHeader(http.StatusOK)
}
}