Skip to content

Commit

Permalink
support frp's websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Jul 27, 2021
1 parent 7282440 commit 4050847
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
20 changes: 2 additions & 18 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,6 @@ func (s *server) CloneWithNewAddress(bindAddress string) Server {
}
}

func isWsUpgrade(header http.Header) bool {
if v := header.Get("Connection"); len(v) == 0 {
return false
}
if v := header.Get("Upgrade"); len(v) == 0 {
return false
}
if v := header.Get("Sec-Websocket-Version"); len(v) == 0 {
return false
}
if v := header.Get("Sec-Websocket-Key"); len(v) == 0 {
return false
}
return true
}

var replacer = strings.NewReplacer("+", "-", "/", "_", "=", "")

func decodeEd(s string) ([]byte, error) {
Expand Down Expand Up @@ -100,7 +84,7 @@ func (s *normalServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

go func() {
defer close(ch)
if !isWsUpgrade(r.Header) {
if !websocket.IsWebSocketUpgrade(r) {
return
}
tcp, err := net.Dial("tcp", s.DestAddress)
Expand Down Expand Up @@ -160,7 +144,7 @@ func (s *internalServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request

go func() {
defer close(ch)
if !isWsUpgrade(r.Header) {
if !websocket.IsWebSocketUpgrade(r) {
return
}
// send inHeader to client for Xray's 0rtt ws
Expand Down
2 changes: 1 addition & 1 deletion tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func WsToTcp(ws *websocket.Conn, tcp net.Conn) (err error) {
if err != nil {
break
}
if msgType != websocket.BinaryMessage {
if msgType != websocket.BinaryMessage && msgType != websocket.TextMessage {
log.Println("unknown msgType")
}
}
Expand Down

0 comments on commit 4050847

Please sign in to comment.