From 5c59255b41da566b37e32c1598b65e0612655618 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sun, 4 Sep 2022 16:13:48 +0200 Subject: [PATCH] Also warn in DERP server if Websockets are not properly working --- derp_server.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/derp_server.go b/derp_server.go index 6fe897bb..fa2b27f6 100644 --- a/derp_server.go +++ b/derp_server.go @@ -99,10 +99,13 @@ func (h *Headscale) DERPHandler( req *http.Request, ) { log.Trace().Caller().Msgf("/derp request from %v", req.RemoteAddr) - up := strings.ToLower(req.Header.Get("Upgrade")) - if up != "websocket" && up != "derp" { - if up != "" { - log.Warn().Caller().Msgf("Weird websockets connection upgrade: %q", up) + upgrade := strings.ToLower(req.Header.Get("Upgrade")) + + if upgrade != "websocket" && upgrade != "derp" { + if upgrade != "" { + log.Warn(). + Caller(). + Msg("No Upgrade header in DERP server request. If headscale is behind a reverse proxy, make sure it is configured to pass WebSockets through.") } writer.Header().Set("Content-Type", "text/plain") writer.WriteHeader(http.StatusUpgradeRequired)