justmao945 / mallory

HTTP/HTTPS proxy over SSH
MIT License
324 stars 68 forks source link

Add health check path #16

Open mdavis-xyz opened 3 years ago

mdavis-xyz commented 3 years ago

I want to deploy mallory using AWS auto-scaling groups, with a health check to detect when something breaks, so it automatically spins up a new instance in another availability zone, to connect the SSH tunnel via another route. (My SSH server is quite unreliable.)

I think the solution is to modify server.go, to add another path next to /reload for direct non-proxied requests.

    } else if r.URL.Path == "/reload" {
        self.reload(w, r)
    } else if r.URL.Path == "/health" {
                self.health(w, r)
    } else {
        L.Printf("%s is not a full URL path\n", r.RequestURI)
    }
...
func (self *Server) health(w http.ResponseWriter, r *http.Request) {
    healthiness = ????
    if healthiness {
        w.WriteHeader(200)
        w.Write([]byte(self.Cfg.Path + " healthy"))
    } else {
        w.WriteHeader(500)
        w.Write([]byte(self.Cfg.Path + " unhealthy"))
    }
}

(Note that I don't know how to write golang, so I'm not quite sure what's happening inside the .Write() calls)

My main question is what goes where ???? is? Is there some attribute/method I can grab from self to return a True if the SSH tunnel is up, and False otherwise?