Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #278 from vania-pooh/master
Browse files Browse the repository at this point in the history
Correctly proxying devtools with ReverseProxy
  • Loading branch information
vania-pooh authored Jun 24, 2019
2 parents b3bf3fd + 2473ee0 commit 21c4001
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ sudo: required
language: go

go:
- 1.11.x
- 1.12.5

services:
- docker
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.adoc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 6 additions & 24 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/abbot/go-http-auth"
"io"
"io/ioutil"
"log"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit 21c4001

Please sign in to comment.