master
dingjun 4 years ago
parent 734613015e
commit 5111aed35d

@ -50,6 +50,10 @@ func forwardWS2WS(conn1, conn2 *websocket.Conn) {
func forwardWS2TCP(conn1 *websocket.Conn, conn2 net.Conn) { func forwardWS2TCP(conn1 *websocket.Conn, conn2 net.Conn) {
ch := make(chan struct{}, 2) ch := make(chan struct{}, 2)
defer func() {
log.Debugf("forward to %s finished", conn2.RemoteAddr())
}()
go func() { go func() {
for { for {
_, data, err := conn1.ReadMessage() _, data, err := conn1.ReadMessage()

@ -38,6 +38,10 @@ func (srv *tcpServer) serve(c net.Conn) {
log.Debugf("connected from %s, forward to %s", c.RemoteAddr(), srv.remote) log.Debugf("connected from %s, forward to %s", c.RemoteAddr(), srv.remote)
defer func() {
log.Debugf("from %s, finished", c.RemoteAddr())
}()
if u.Scheme == "ws" || u.Scheme == "wss" { if u.Scheme == "ws" || u.Scheme == "wss" {
conn1, resp, err := dialer.Dial(srv.remote, nil) conn1, resp, err := dialer.Dial(srv.remote, nil)
if err != nil { if err != nil {

@ -46,7 +46,18 @@ func (wss *wsServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
log.Debugf("request %s, forward to %s", p, remote) ip := r.RemoteAddr
_ip := r.Header.Get("x-real-ip")
if _ip != "" {
ip = _ip
}
log.Debugf("from %s, request %s, forward to %s", ip, p, remote)
defer func() {
log.Debugf("from %s, request finished", ip)
}()
conn, err := upgrader.Upgrade(w, r, nil) conn, err := upgrader.Upgrade(w, r, nil)
if err != nil { if err != nil {

Loading…
Cancel
Save