handleClientHandler is the main http websocket handler for the chisel server
(w http.ResponseWriter, r *http.Request)
| 16 | |
| 17 | // handleClientHandler is the main http websocket handler for the chisel server |
| 18 | func (s *Server) handleClientHandler(w http.ResponseWriter, r *http.Request) { |
| 19 | //websockets upgrade AND has chisel prefix |
| 20 | upgrade := strings.ToLower(r.Header.Get("Upgrade")) |
| 21 | protocol := r.Header.Get("Sec-WebSocket-Protocol") |
| 22 | if upgrade == "websocket" { |
| 23 | if protocol == chshare.ProtocolVersion { |
| 24 | s.handleWebsocket(w, r) |
| 25 | return |
| 26 | } |
| 27 | //print into server logs and silently fall-through |
| 28 | s.Infof("ignored client connection using protocol '%s', expected '%s'", |
| 29 | protocol, chshare.ProtocolVersion) |
| 30 | } |
| 31 | //proxy target was provided |
| 32 | if s.reverseProxy != nil { |
| 33 | s.reverseProxy.ServeHTTP(w, r) |
| 34 | return |
| 35 | } |
| 36 | //no proxy defined, provide access to health/version checks |
| 37 | switch r.URL.Path { |
| 38 | case "/health": |
| 39 | w.Write([]byte("OK\n")) |
| 40 | return |
| 41 | case "/version": |
| 42 | w.Write([]byte(chshare.BuildVersion)) |
| 43 | return |
| 44 | } |
| 45 | //missing :O |
| 46 | w.WriteHeader(404) |
| 47 | w.Write([]byte("Not found")) |
| 48 | } |
| 49 | |
| 50 | // handleWebsocket is responsible for handling the websocket connection |
| 51 | func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) { |
nothing calls this directly
no test coverage detected