mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-22 23:13:01 +00:00
HTTPUpgrade 0-RTT (#3152)
* Add ed to enable HTTPUpgrade 0-RTT https://github.com/XTLS/Xray-core/issues/3128#issuecomment-2002563369 * WebSocket hub.go MaxHeaderBytes: 4096 -> 8192
This commit is contained in:
parent
69e1734e3a
commit
18b823b4a6
@ -172,12 +172,10 @@ func (c *WebSocketConfig) Build() (proto.Message, error) {
|
||||
}
|
||||
}
|
||||
config := &websocket.Config{
|
||||
Path: path,
|
||||
Header: header,
|
||||
Ed: ed,
|
||||
}
|
||||
if c.AcceptProxyProtocol {
|
||||
config.AcceptProxyProtocol = c.AcceptProxyProtocol
|
||||
Path: path,
|
||||
Header: header,
|
||||
AcceptProxyProtocol: c.AcceptProxyProtocol,
|
||||
Ed: ed,
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
@ -190,12 +188,22 @@ type HttpUpgradeConfig struct {
|
||||
|
||||
// Build implements Buildable.
|
||||
func (c *HttpUpgradeConfig) Build() (proto.Message, error) {
|
||||
config := &httpupgrade.Config{
|
||||
Path: c.Path,
|
||||
Host: c.Host,
|
||||
path := c.Path
|
||||
var ed uint32
|
||||
if u, err := url.Parse(path); err == nil {
|
||||
if q := u.Query(); q.Get("ed") != "" {
|
||||
Ed, _ := strconv.Atoi(q.Get("ed"))
|
||||
ed = uint32(Ed)
|
||||
q.Del("ed")
|
||||
u.RawQuery = q.Encode()
|
||||
path = u.String()
|
||||
}
|
||||
}
|
||||
if c.AcceptProxyProtocol {
|
||||
config.AcceptProxyProtocol = c.AcceptProxyProtocol
|
||||
config := &httpupgrade.Config{
|
||||
Path: path,
|
||||
Host: c.Host,
|
||||
AcceptProxyProtocol: c.AcceptProxyProtocol,
|
||||
Ed: ed,
|
||||
}
|
||||
return config, nil
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.32.0
|
||||
// protoc v4.25.1
|
||||
// protoc v4.23.1
|
||||
// source: transport/internet/httpupgrade/config.proto
|
||||
|
||||
package httpupgrade
|
||||
@ -28,6 +28,7 @@ type Config struct {
|
||||
Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"`
|
||||
Host string `protobuf:"bytes,3,opt,name=host,proto3" json:"host,omitempty"`
|
||||
AcceptProxyProtocol bool `protobuf:"varint,4,opt,name=accept_proxy_protocol,json=acceptProxyProtocol,proto3" json:"accept_proxy_protocol,omitempty"`
|
||||
Ed uint32 `protobuf:"varint,5,opt,name=ed,proto3" json:"ed,omitempty"`
|
||||
}
|
||||
|
||||
func (x *Config) Reset() {
|
||||
@ -83,6 +84,13 @@ func (x *Config) GetAcceptProxyProtocol() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *Config) GetEd() uint32 {
|
||||
if x != nil {
|
||||
return x.Ed
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
var File_transport_internet_httpupgrade_config_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_transport_internet_httpupgrade_config_proto_rawDesc = []byte{
|
||||
@ -91,13 +99,14 @@ var file_transport_internet_httpupgrade_config_proto_rawDesc = []byte{
|
||||
0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x23, 0x78,
|
||||
0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e,
|
||||
0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68, 0x74, 0x74, 0x70, 0x75, 0x70, 0x67, 0x72, 0x61,
|
||||
0x64, 0x65, 0x22, 0x6a, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x64, 0x65, 0x22, 0x7a, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04,
|
||||
0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04,
|
||||
0x68, 0x6f, 0x73, 0x74, 0x12, 0x32, 0x0a, 0x15, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x5f, 0x70,
|
||||
0x72, 0x6f, 0x78, 0x79, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x04, 0x20,
|
||||
0x01, 0x28, 0x08, 0x52, 0x13, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x50, 0x72, 0x6f, 0x78, 0x79,
|
||||
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x42, 0x8b,
|
||||
0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x0e, 0x0a, 0x02, 0x65, 0x64, 0x18, 0x05,
|
||||
0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x65, 0x64, 0x4a, 0x04, 0x08, 0x01, 0x10, 0x02, 0x42, 0x8b,
|
||||
0x01, 0x0a, 0x27, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e,
|
||||
0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x68,
|
||||
0x74, 0x74, 0x70, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x50, 0x01, 0x5a, 0x38, 0x67, 0x69,
|
||||
|
@ -13,4 +13,6 @@ message Config {
|
||||
string host = 3;
|
||||
|
||||
bool accept_proxy_protocol = 4;
|
||||
}
|
||||
|
||||
uint32 ed = 5;
|
||||
}
|
||||
|
@ -81,7 +81,20 @@ func dialhttpUpgrade(ctx context.Context, dest net.Destination, streamSettings *
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ConnRF{Conn: conn, Req: req, First: true}, nil
|
||||
connRF := &ConnRF{
|
||||
Conn: conn,
|
||||
Req: req,
|
||||
First: true,
|
||||
}
|
||||
|
||||
if transportConfiguration.Ed == 0 {
|
||||
_, err = connRF.Read([]byte{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return connRF, nil
|
||||
}
|
||||
|
||||
func dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (stat.Connection, error) {
|
||||
|
@ -129,7 +129,7 @@ func ListenWS(ctx context.Context, address net.Address, port net.Port, streamSet
|
||||
ln: l,
|
||||
},
|
||||
ReadHeaderTimeout: time.Second * 4,
|
||||
MaxHeaderBytes: 4096,
|
||||
MaxHeaderBytes: 8192,
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
Loading…
Reference in New Issue
Block a user