Files
v2ray_simple/httpLayer/fallback.go
e1732a364fed 3e7e779920 修订代码; 完善ws; 令Pool使用指针,而不是slice
令 websocket在path访问正确但是不是ws连接时,也进行回落,而不是返回一个错误

将 GetH1RequestMethod_and_PATH_from_Bytes 改名为 ParseH1Request, 且支持 读取header

同时新增了 RawHeader 结构 用于 上述目的。httpLayer还添加了 CanonicalizeHeaderKey 方法。

令Pool使用指针 后,测速从 3200左右上升至3800左右,也不知道是不是这个优化导致的。如果是的话,那也太猛了。
2022-05-07 09:51:45 +08:00

80 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package httpLayer
import (
"errors"
"github.com/e1732a364fed/v2ray_simple/netLayer"
)
const (
Fallback_none = 0
)
const (
FallBack_default byte = 1 << iota //default 其实也是path只不过path是通配符。
//这里剩余fallback按该固定顺序排列. 这是为了方便代码的书写(alpn和sni都是tls的)
// 虽然alpn和sni都是tls的但是回落本身是专门用于http的所以还是放在httpLayer包中
Fallback_path
Fallback_alpn
Fallback_sni
fallback_end
all_non_default_fallbacktype_count = iota - 2
//alpn_unspecified = 0
)
const (
alpn_http11 = 1 << iota
alpn_http20
)
var ErrShouldFallback = errors.New("will fallback")
func getfallbacktype_byindex(i int) byte {
return 1 << (i + 1)
}
//判断 Fallback.SupportType 返回的 数值 是否具有特定的Fallback类型
func HasFallbackType(ftype, b byte) bool {
return ftype&b > 0
}
//实现 Fallback. 这里的fallback只与http协议有关所以只能按path,alpn 和 sni 进行分类
type Fallback interface {
GetFallback(ftype byte, params ...string) *FallbackResult
SupportType() byte //参考Fallback_开头的常量。如果支持多个则返回它们 按位与 的结果
}
type FallbackResult struct {
Addr netLayer.Addr
Xver int
}
func (r *FallbackResult) GetFallback(ftype byte, _ ...string) *FallbackResult {
return r
}
func (FallbackResult) SupportType() byte {
return FallBack_default
}
type FallbackConf struct {
//可选
FromTag []string `toml:"from" json:"from"` //which inServer triggered this fallback
Xver int `toml:"xver" json:"xver"` //use PROXY protocol or not, and which version
//必填
Dest any `toml:"dest" json:"dest"` //see netLayer.NewAddrFromAny for details about "any" addr
//几种匹配方式,可选
Path string `toml:"path" json:"path"`
Sni string `toml:"sni" json:"sni"`
Alpn []string `toml:"alpn" json:"alpn"`
}