diff options
| author | zc <zc2638@qq.com> | 2021-10-20 11:34:01 +0800 |
|---|---|---|
| committer | zc <zc2638@qq.com> | 2021-10-20 11:41:31 +0800 |
| commit | 38881727195b3783dd0ff64fb6fec8c721542f48 (patch) | |
| tree | 165677ed4575ffb4d3115fade49af5d486ef0320 /staging | |
| parent | Merge pull request #3215 from gy95/typ (diff) | |
| download | kubeedge-38881727195b3783dd0ff64fb6fec8c721542f48.tar.gz | |
clone the header in the correct way
Signed-off-by: zc <zc2638@qq.com>
Diffstat (limited to 'staging')
3 files changed, 2 insertions, 28 deletions
diff --git a/staging/src/github.com/kubeedge/viaduct/pkg/client/ws.go b/staging/src/github.com/kubeedge/viaduct/pkg/client/ws.go index f0bf0b836..d2f7c95d3 100644 --- a/staging/src/github.com/kubeedge/viaduct/pkg/client/ws.go +++ b/staging/src/github.com/kubeedge/viaduct/pkg/client/ws.go @@ -10,7 +10,6 @@ import ( "github.com/kubeedge/viaduct/pkg/api" "github.com/kubeedge/viaduct/pkg/conn" "github.com/kubeedge/viaduct/pkg/lane" - "github.com/kubeedge/viaduct/pkg/utils" ) // the client based on websocket @@ -58,7 +57,7 @@ func (c *WSClient) Connect() (conn.Connection, error) { CtrlLane: lane.NewLane(api.ProtocolTypeWS, wsConn), State: &conn.ConnectionState{ State: api.StatConnected, - Headers: utils.DeepCopyHeader(c.exOpts.Header), + Headers: c.exOpts.Header.Clone(), }, AutoRoute: c.options.AutoRoute, }), nil diff --git a/staging/src/github.com/kubeedge/viaduct/pkg/server/ws.go b/staging/src/github.com/kubeedge/viaduct/pkg/server/ws.go index f4d8d89b7..3a338d32e 100644 --- a/staging/src/github.com/kubeedge/viaduct/pkg/server/ws.go +++ b/staging/src/github.com/kubeedge/viaduct/pkg/server/ws.go @@ -12,7 +12,6 @@ import ( "github.com/kubeedge/viaduct/pkg/api" "github.com/kubeedge/viaduct/pkg/conn" "github.com/kubeedge/viaduct/pkg/lane" - "github.com/kubeedge/viaduct/pkg/utils" ) // websocket protocol server @@ -89,7 +88,7 @@ func (srv *WSServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { CtrlLane: lane.NewLane(api.ProtocolTypeWS, wsConn), State: &conn.ConnectionState{ State: api.StatConnected, - Headers: utils.DeepCopyHeader(req.Header), + Headers: req.Header.Clone(), }, AutoRoute: srv.options.AutoRoute, }) diff --git a/staging/src/github.com/kubeedge/viaduct/pkg/utils/utils.go b/staging/src/github.com/kubeedge/viaduct/pkg/utils/utils.go deleted file mode 100644 index 1954a1087..000000000 --- a/staging/src/github.com/kubeedge/viaduct/pkg/utils/utils.go +++ /dev/null @@ -1,24 +0,0 @@ -package utils - -import ( - "encoding/json" - "net/http" - - "k8s.io/klog/v2" -) - -func DeepCopyHeader(header http.Header) http.Header { - headerByte, err := json.Marshal(header) - if err != nil { - klog.Errorf("faile to marshal header, error:%+v", err) - return nil - } - - dstHeader := make(http.Header) - err = json.Unmarshal(headerByte, &dstHeader) - if err != nil { - klog.Errorf("failed to unmarshal header, error:%+v", err) - return nil - } - return dstHeader -} |
