mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: ipv6-only mode compatibility fixes (#23031)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
@@ -102,7 +103,7 @@ func (s *WebsocketServer) initWs(w http.ResponseWriter, r *http.Request) error {
|
||||
}
|
||||
|
||||
var err error
|
||||
addr := fmt.Sprintf("%s:%d", s.Host, s.Port)
|
||||
addr := net.JoinHostPort(s.Host, strconv.Itoa(s.Port))
|
||||
s.conn, s.sshNetConn, err = NewSshClient("tcp", addr, config)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "dial %s", addr)
|
||||
|
||||
@@ -19,9 +19,11 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/webconsole/session"
|
||||
@@ -69,7 +71,7 @@ func (s *WebsockifyServer) isBase64Subprotocol(wsConn *websocket.Conn) bool {
|
||||
}
|
||||
|
||||
func (s *WebsockifyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
targetAddr := fmt.Sprintf("%s:%d", s.TargetHost, s.TargetPort)
|
||||
log.Debugf("ServeHTTP: %s, %s", r.URL.String(), jsonutils.Marshal(r.Header))
|
||||
wsConn, err := upgrader.Upgrade(w, r, nil)
|
||||
if err != nil {
|
||||
log.Errorf("New websocket connection error: %v", err)
|
||||
@@ -77,6 +79,7 @@ func (s *WebsockifyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
log.Debugf("Get coordinate subprotocol: %s", wsConn.Subprotocol())
|
||||
|
||||
targetAddr := net.JoinHostPort(s.TargetHost, strconv.Itoa(int(s.TargetPort)))
|
||||
log.Debugf("Handle websocket connect, target: %s", targetAddr)
|
||||
targetConn, err := net.Dial("tcp", targetAddr)
|
||||
if err != nil {
|
||||
@@ -89,6 +92,7 @@ func (s *WebsockifyServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (s *WebsockifyServer) doProxy(wsConn *websocket.Conn, tcpConn net.Conn) {
|
||||
log.Infof("doProxy bewteen ws: %s <--> tcp: %s", wsConn.RemoteAddr(), tcpConn.RemoteAddr())
|
||||
s.Session.RegisterDuplicateHook(func() {
|
||||
wsConn.Close()
|
||||
tcpConn.Close()
|
||||
|
||||
Reference in New Issue
Block a user