From 502d83c52fcf696e21aa79797e4f38f15a9dc6cd Mon Sep 17 00:00:00 2001 From: e1732a364fed <75717694+e1732a364fed@users.noreply.github.com> Date: Sat, 1 Jan 2000 00:00:00 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BB=A4ws=E5=9C=A8fallback=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=BB=99=E5=87=BA=E5=85=B7=E4=BD=93=E5=8E=9F=E5=9B=A0;fix=20#1?= =?UTF-8?q?94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- advLayer/ws/server.go | 7 ++++++- cmd/verysimple/main.go | 6 +++--- httpLayer/fallback.go | 5 +++-- main.go | 1 + 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/advLayer/ws/server.go b/advLayer/ws/server.go index 10602c4..b520977 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 1787be5..a845b17 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 8a77581..9858e41 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 94e6294..2ca4d9c 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),