Files
v2ray_simple/advLayer/ws/ws.go
e1732a364fed cc758dec66 全面修订代码;完成 grpcSimple包;使用 tag选择编译quic 和 grpc
grpcSimple包的服务端和客户端现在都已完成,且兼容v2ray等内核。
grpcSimple包 简洁、高效,更加科学。暂不支持multiMode。

若 grpc_full 给出,则使用grpc包,否则默认使用 grpcSimple包。
若 noquic给出,则不使用 quic,否则 默认使用 quic。

修复 ws early 失效问题;
2022-04-28 05:41:56 +08:00

59 lines
1.5 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 ws implements websocket handshake.
Reference
websocket rfc: https://datatracker.ietf.org/doc/html/rfc6455/
下面把一个握手放在这里作为参考
请求
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
Origin: http://example.com
响应
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: HSmrc0sMlYUkAGmm5OPpG2HaGWk=
Sec-WebSocket-Protocol: chat
总之一个websocket的请求头直接就是一个 合法的http请求头所以也没必要额外包一个http连接
直接使用tcp/tls 连接即可。
websocket 库比较 https://yalantis.com/blog/how-to-build-websockets-in-go/
中文翻译:
https://tonybai.com/2019/09/28/how-to-build-websockets-in-go/
总之 gobwas/ws 是最好的库. 本包使用 gobwas/ws
*/
package ws
import "github.com/e1732a364fed/v2ray_simple/advLayer"
func init() {
advLayer.ProtocolsMap["ws"] = Creator{}
}
type Creator struct{}
func (Creator) NewClientFromConf(conf *advLayer.Conf) (advLayer.Client, error) {
return NewClient(conf.Host, conf.Path, conf.Headers, conf.IsEarly)
}
func (Creator) NewServerFromConf(conf *advLayer.Conf) (advLayer.Server, error) {
return NewServer(conf.Path, conf.Headers, conf.IsEarly), nil
}
func (Creator) GetDefaultAlpn() (alpn string, mustUse bool) {
return
}
func (Creator) PackageID() string {
return "ws"
}