From 2473ee0804e0916e8f840e143da4c2ee9322db6d Mon Sep 17 00:00:00 2001 From: Ivan Krutov Date: Fri, 21 Jun 2019 12:00:54 +0300 Subject: [PATCH] Correctly proxying devtools with ReverseProxy --- .travis.yml | 2 +- docs/contributing.adoc | 2 +- proxy.go | 30 ++++++------------------------ 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6947cd5..846b7fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ sudo: required language: go go: - - 1.11.x + - 1.12.5 services: - docker diff --git a/docs/contributing.adoc b/docs/contributing.adoc index c7ee1ed..0858ab5 100644 --- a/docs/contributing.adoc +++ b/docs/contributing.adoc @@ -1,7 +1,7 @@ == Contributing & Development To build Ggr: -. Install https://golang.org/doc/install[Golang] 1.11 and above +. Install https://golang.org/doc/install[Golang] 1.12 and above . Clone Ggr source: $ git clone https://github.com/aerokube/ggr.git diff --git a/proxy.go b/proxy.go index dfc6f6e..93e01d9 100644 --- a/proxy.go +++ b/proxy.go @@ -6,6 +6,7 @@ import ( "encoding/json" "encoding/xml" "fmt" + "github.com/abbot/go-http-auth" "io" "io/ioutil" "log" @@ -14,13 +15,11 @@ import ( "net/http/httputil" "net/url" "reflect" - "strconv" "strings" "sync" "sync/atomic" "time" - "github.com/abbot/go-http-auth" . "github.com/aerokube/ggr/config" "golang.org/x/net/websocket" ) @@ -689,27 +688,10 @@ func proxyConn(id uint64, wsconn *websocket.Conn, conn net.Conn, err error, sess log.Printf("[%d] [-] [WS_CLIENT_DISCONNECTED] [-] [-] [-] [%s] [%s] [-] [-]", id, address, sessionID) } -func devtools(wsconn *websocket.Conn) { - defer wsconn.Close() - confLock.RLock() - defer confLock.RUnlock() - - id := serial() - head := len(paths.Devtools) - tail := head + md5SumLength - path := wsconn.Request().URL.Path - if len(path) < tail { - log.Printf("[%d] [-] [INVALID_DEVTOOLS_REQUEST_URL] [-] [-] [%s] [-] [-] [-] [-]", id, path) - return - } - sum := path[head:tail] - h, ok := routes[sum] - if ok { - sessionID := strings.Split(path, "/")[2][md5SumLength:] - proxyWebSockets(id, wsconn, sessionID, h.Name, strconv.Itoa(h.Port), "/devtools") - } else { - log.Printf("[%d] [-] [UNKNOWN_DEVTOOLS_HOST] [-] [-] [-] [-] [%s] [-] [-]", id, sum) - } +func devtools(w http.ResponseWriter, r *http.Request) { + proxyStatic(w, r, paths.Devtools, "INVALID_DEVTOOLS_REQUEST_URL", "PROXYING_DEVTOOLS", "UNKNOWN_DEVTOOLS_HOST", func(remainder string) string { + return fmt.Sprintf("/devtools/%s", remainder) + }) } func video(w http.ResponseWriter, r *http.Request) { @@ -784,6 +766,6 @@ func mux() http.Handler { mux.HandleFunc(paths.Logs, WithSuitableAuthentication(authenticator, logs)) mux.HandleFunc(paths.Download, WithSuitableAuthentication(authenticator, download)) mux.HandleFunc(paths.Clipboard, WithSuitableAuthentication(authenticator, clipboard)) - mux.Handle(paths.Devtools, websocket.Handler(devtools)) + mux.HandleFunc(paths.Devtools, devtools) return mux }