mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-12-24 13:27:56 +08:00
令ws在fallback失败给出具体原因;fix #194
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -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_开头的常量。如果支持多个,则返回它们 按位与 的结果
|
||||
|
||||
1
main.go
1
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),
|
||||
|
||||
Reference in New Issue
Block a user