diff --git a/advLayer/ws/server.go b/advLayer/ws/server.go index 10602c48..b5209777 100644 --- a/advLayer/ws/server.go +++ b/advLayer/ws/server.go @@ -23,7 +23,7 @@ var ( upgradeBs = []byte("Upgrade") ) -//implements advLayer.SingleServer +// implements advLayer.SingleServer type Server struct { Creator UseEarlyData bool @@ -123,6 +123,7 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) { optionalFirstBuffer := rp.WholeRequestBuf notWsRequest := false + notReason := "" //因为 gobwas 会先自行给错误的连接 返回 错误信息,而这不行,所以我们先过滤一遍。 //header 我们只过滤一个 connection 就行. 要是怕攻击者用 “对的path,method 和错误的header” 进行探测, @@ -130,6 +131,7 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) { 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 @@ -147,6 +149,7 @@ func (s *Server) Handshake(underlay net.Conn) (net.Conn, error) { } if !hasUpgrade { notWsRequest = true + notReason = "has no upgrade field" } } @@ -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 } @@ -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 } diff --git a/cmd/verysimple/main.go b/cmd/verysimple/main.go index 1787be54..a845b17f 100644 --- a/cmd/verysimple/main.go +++ b/cmd/verysimple/main.go @@ -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: diff --git a/httpLayer/fallback.go b/httpLayer/fallback.go index 8a775819..9858e417 100644 --- a/httpLayer/fallback.go +++ b/httpLayer/fallback.go @@ -44,6 +44,7 @@ type FallbackMeta struct { Path string Method string IsH2 bool + Reason string H2Request *http.Request } @@ -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_开头的常量。如果支持多个,则返回它们 按位与 的结果 diff --git a/main.go b/main.go index 94e6294d..2ca4d9c4 100644 --- a/main.go +++ b/main.go @@ -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),