Skip to content

Commit

Permalink
Added defaultErrorHandler correctly processing client disconnected cl…
Browse files Browse the repository at this point in the history
…ients (fixes #594)
  • Loading branch information
vania-pooh committed Dec 28, 2018
1 parent 2cfcb68 commit 9cb4984
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea
*.iml
selenoid
selenoid.exe
coverage.*
.DS_Store
12 changes: 11 additions & 1 deletion selenoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ func proxy(w http.ResponseWriter, r *http.Request) {
defer func() {
done <- cancel
}()
requestId := serial()
(&httputil.ReverseProxy{
Director: func(r *http.Request) {
requestId := serial()
fragments := strings.Split(r.URL.Path, slash)
id := fragments[2]
sess, ok := sessions.Get(id)
Expand Down Expand Up @@ -448,9 +448,18 @@ func proxy(w http.ResponseWriter, r *http.Request) {
}
r.URL.Path = errorPath
},
ErrorHandler: defaultErrorHandler(requestId),
}).ServeHTTP(w, r)
}

func defaultErrorHandler(requestId uint64) func(http.ResponseWriter, *http.Request, error) {
return func(w http.ResponseWriter, r *http.Request, err error) {
user, remote := util.RequestInfo(r)
log.Printf("[%d] [CLIENT_DISCONNECTED] [%s] [%s] [Error: %v]", requestId, user, remote, err)
w.WriteHeader(http.StatusBadGateway)
}
}

func reverseProxy(hostFn func(sess *session.Session) string, status string) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
requestId := serial()
Expand All @@ -464,6 +473,7 @@ func reverseProxy(hostFn func(sess *session.Session) string, status string) func
r.URL.Path = remainingPath
log.Printf("[%d] [%s] [%s] [%s]", requestId, status, sid, remainingPath)
},
ErrorHandler: defaultErrorHandler(requestId),
}).ServeHTTP(w, r)
} else {
util.JsonError(w, fmt.Sprintf("Unknown session %s", sid), http.StatusNotFound)
Expand Down

0 comments on commit 9cb4984

Please sign in to comment.