From c55b7283ec61463876f0b5336ca6848587086eb2 Mon Sep 17 00:00:00 2001 From: Anders Pitman Date: Sat, 26 Sep 2020 15:47:56 -0600 Subject: [PATCH] Implement tunnel delete --- boringproxy.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/boringproxy.go b/boringproxy.go index 320916b..9146478 100644 --- a/boringproxy.go +++ b/boringproxy.go @@ -58,6 +58,8 @@ func (p *BoringProxy) handleAdminRequest(w http.ResponseWriter, r *http.Request) func (p *BoringProxy) handleTunnels(w http.ResponseWriter, r *http.Request) { fmt.Println("handleTunnels") + query := r.URL.Query() + if r.Method == "GET" { body, err := json.Marshal(p.tunMan.tunnels) if err != nil { @@ -68,6 +70,15 @@ func (p *BoringProxy) handleTunnels(w http.ResponseWriter, r *http.Request) { w.Write([]byte(body)) } else if r.Method == "POST" { p.handleCreateTunnel(w, r) + } else if r.Method == "DELETE" { + if len(query["host"]) != 1 { + w.WriteHeader(400) + w.Write([]byte("Invalid host parameter")) + return + } + host := query["host"][0] + + p.tunMan.DeleteTunnel(host) } } @@ -198,6 +209,12 @@ func (m *TunnelManager) SetTunnel(host string, port int) { m.mutex.Unlock() } +func (m *TunnelManager) DeleteTunnel(host string) { + m.mutex.Lock() + delete(m.tunnels, host) + m.mutex.Unlock() +} + func (m *TunnelManager) GetPort(serverName string) (int, error) { m.mutex.Lock() port, exists := m.tunnels[serverName]