Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

Commit

Permalink
令ws在fallback失败给出具体原因;fix #194
Browse files Browse the repository at this point in the history
  • Loading branch information
e1732a364fed committed Dec 12, 2022
1 parent d9bfd00 commit 502d83c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion advLayer/ws/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
upgradeBs = []byte("Upgrade")
)

//implements advLayer.SingleServer
// implements advLayer.SingleServer
type Server struct {
Creator
UseEarlyData bool
Expand Down Expand Up @@ -123,13 +123,15 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) {
optionalFirstBuffer := rp.WholeRequestBuf

notWsRequest := false
notReason := ""

//因为 gobwas 会先自行给错误的连接 返回 错误信息,而这不行,所以我们先过滤一遍。
//header 我们只过滤一个 connection 就行. 要是怕攻击者用 “对的path,method 和错误的header” 进行探测,
// 那你设一个复杂的path就ok了。

if rp.Method != "GET" || s.Thepath != rp.Path || len(rp.Headers) == 0 {
notWsRequest = true
notReason = `rp.Method != "GET" || s.Thepath != rp.Path || len(rp.Headers) == 0`

} else {
hasUpgrade := false
Expand All @@ -147,6 +149,7 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) {
}
if !hasUpgrade {
notWsRequest = true
notReason = "has no upgrade field"
}

}
Expand All @@ -157,6 +160,7 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) {
H1RequestBuf: optionalFirstBuffer,
Path: rp.Path,
Method: rp.Method,
Reason: notReason,
}, httpLayer.ErrShouldFallback
}

Expand Down Expand Up @@ -279,6 +283,7 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) {
H1RequestBuf: optionalFirstBuffer,
Path: rp.Path,
Method: rp.Method,
Reason: err.Error(),
}, httpLayer.ErrShouldFallback
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/verysimple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,12 @@ func mainFunc() (result int) {
//load inServers and RoutingEnv
switch configMode {
case proxy.SimpleMode:
var theServer proxy.Server
result, theServer = loadSimpleServer()
//var theServer proxy.Server
result, _ = loadSimpleServer()
if result < 0 {
return result
}
allServers = append(allServers, theServer)
//allServers = append(allServers, theServer) //loadSimpleServer 已经加过一遍了

case proxy.StandardMode:

Expand Down
5 changes: 3 additions & 2 deletions httpLayer/fallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type FallbackMeta struct {
Path string
Method string
IsH2 bool
Reason string

H2Request *http.Request
}
Expand All @@ -52,12 +53,12 @@ func getfallbacktype_byindex(i int) byte {
return 1 << (i + 1)
}

//判断 Fallback.SupportType 返回的 数值 是否具有特定的Fallback类型
// 判断 Fallback.SupportType 返回的 数值 是否具有特定的Fallback类型
func HasFallbackType(ftype, b byte) bool {
return ftype&b > 0
}

//实现 Fallback. 这里的fallback只与http协议有关,所以只能按path,alpn 和 sni 进行分类
// 实现 Fallback. 这里的fallback只与http协议有关,所以只能按path,alpn 和 sni 进行分类
type Fallback interface {
GetFallback(ftype byte, params ...string) *FallbackResult
SupportType() byte //参考Fallback_开头的常量。如果支持多个,则返回它们 按位与 的结果
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func handleNewIncomeConnection(inServer proxy.Server, defaultClientForThis proxy
ce.Write(
zap.String("handler", inServer.AddrStr()),
zap.String("advLayer", adv),
zap.String("Reason", meta.Reason),
zap.String("validPath", advSer.GetPath()),
zap.String("gotMethod", meta.Method),
zap.String("gotPath", meta.Path),
Expand Down

0 comments on commit 502d83c

Please sign in to comment.