From 7866a5a369d9bf7953efb1f6f538c8ca1149db18 Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Fri, 22 Sep 2023 12:03:04 +0800 Subject: [PATCH] proxyserver --- proxyserver/main.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/proxyserver/main.go b/proxyserver/main.go index 91ffa076..1b0b9f9c 100644 --- a/proxyserver/main.go +++ b/proxyserver/main.go @@ -209,22 +209,22 @@ func NewBackend(mux *http.ServeMux, httpAddress string, muxPaths ...string) *Bac target := url.URL{Scheme: "ws", Host: strings.Split(backend.HttpAddress, "//")[1], Path: r.URL.Path} var transfer = func(src, dest *websocket.Conn) { + defer src.Close() + defer dest.Close() + // TODO: 可以做错误处理 for { mType, msg, err := src.ReadMessage() if err != nil { log.Println(err) - break + return } err = dest.WriteMessage(mType, msg) if err != nil { log.Println(err) - break + return } } - - src.Close() - dest.Close() } header := r.Header.Clone()