mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-19 00:30:58 +00:00
fix: websocket server upgrade in golang1.20
This commit is contained in:
parent
3d2cb992fa
commit
dcb20e2824
3 changed files with 13 additions and 1 deletions
|
@ -555,7 +555,7 @@ func StreamUpgradedWebsocketConn(w http.ResponseWriter, r *http.Request) (net.Co
|
|||
w.Header().Set("Sec-Websocket-Accept", getSecAccept(r.Header.Get("Sec-WebSocket-Key")))
|
||||
}
|
||||
w.WriteHeader(http.StatusSwitchingProtocols)
|
||||
if flusher, isFlusher := w.(interface{ FlushError() error }); isFlusher {
|
||||
if flusher, isFlusher := w.(interface{ FlushError() error }); isFlusher && writeHeaderShouldFlush {
|
||||
err = flusher.FlushError()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("flush response: %w", err)
|
||||
|
|
7
transport/vmess/websocket_go120.go
Normal file
7
transport/vmess/websocket_go120.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
//go:build !go1.21
|
||||
|
||||
package vmess
|
||||
|
||||
// Golang1.20's net.http Flush will mistakenly call w.WriteHeader(StatusOK) internally after w.WriteHeader(http.StatusSwitchingProtocols)
|
||||
// https://github.com/golang/go/issues/59564
|
||||
const writeHeaderShouldFlush = false
|
5
transport/vmess/websocket_go121.go
Normal file
5
transport/vmess/websocket_go121.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
//go:build go1.21
|
||||
|
||||
package vmess
|
||||
|
||||
const writeHeaderShouldFlush = true
|
Loading…
Add table
Reference in a new issue