Skip to content

Commit

Permalink
Also warn in DERP server if Websockets are not properly working
Browse files Browse the repository at this point in the history
  • Loading branch information
juanfont committed Sep 4, 2022
1 parent a377ee1 commit 5c59255
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions derp_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5c59255

Please sign in to comment.