MCPcopy
hub / github.com/jpillora/chisel / handleClientHandler

Method handleClientHandler

server/server_handler.go:18–48  ·  view source on GitHub ↗

handleClientHandler is the main http websocket handler for the chisel server

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

16
17// handleClientHandler is the main http websocket handler for the chisel server
18func (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
51func (s *Server) handleWebsocket(w http.ResponseWriter, req *http.Request) {

Callers

nothing calls this directly

Calls 4

handleWebsocketMethod · 0.95
GetMethod · 0.80
InfofMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected