From 60553a6c262915da32a95b98d654aa437255e1df Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Mon, 29 Jul 2024 06:32:04 +0000 Subject: [PATCH] SplitHTTP server: Add noSSEHeader https://github.com/XTLS/Xray-core/pull/3603#issuecomment-2254968219 --- infra/conf/transport_internet.go | 2 + transport/internet/config.pb.go | 16 ++++---- transport/internet/splithttp/config.pb.go | 48 ++++++++++++++--------- transport/internet/splithttp/config.proto | 1 + transport/internet/splithttp/hub.go | 8 +++- 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/infra/conf/transport_internet.go b/infra/conf/transport_internet.go index 91dc86bebcc2..9e644e43413b 100644 --- a/infra/conf/transport_internet.go +++ b/infra/conf/transport_internet.go @@ -232,6 +232,7 @@ type SplitHTTPConfig struct { MaxConcurrentUploads Int32Range `json:"maxConcurrentUploads"` MaxUploadSize Int32Range `json:"maxUploadSize"` MinUploadIntervalMs Int32Range `json:"minUploadIntervalMs"` + NoSSEHeader bool `json:"noSSEHeader"` } // Build implements Buildable. @@ -260,6 +261,7 @@ func (c *SplitHTTPConfig) Build() (proto.Message, error) { From: c.MinUploadIntervalMs.From, To: c.MinUploadIntervalMs.To, }, + NoSSEHeader: c.NoSSEHeader, } return config, nil } diff --git a/transport/internet/config.pb.go b/transport/internet/config.pb.go index 903fa794660a..f0fe1ea5c6cd 100644 --- a/transport/internet/config.pb.go +++ b/transport/internet/config.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.34.2 -// protoc v5.27.2 +// protoc-gen-go v1.34.1 +// protoc v5.27.0 // source: transport/internet/config.proto package internet @@ -863,7 +863,7 @@ func file_transport_internet_config_proto_rawDescGZIP() []byte { var file_transport_internet_config_proto_enumTypes = make([]protoimpl.EnumInfo, 3) var file_transport_internet_config_proto_msgTypes = make([]protoimpl.MessageInfo, 5) -var file_transport_internet_config_proto_goTypes = []any{ +var file_transport_internet_config_proto_goTypes = []interface{}{ (TransportProtocol)(0), // 0: xray.transport.internet.TransportProtocol (DomainStrategy)(0), // 1: xray.transport.internet.DomainStrategy (SocketConfig_TProxyMode)(0), // 2: xray.transport.internet.SocketConfig.TProxyMode @@ -897,7 +897,7 @@ func file_transport_internet_config_proto_init() { return } if !protoimpl.UnsafeEnabled { - file_transport_internet_config_proto_msgTypes[0].Exporter = func(v any, i int) any { + file_transport_internet_config_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*TransportConfig); i { case 0: return &v.state @@ -909,7 +909,7 @@ func file_transport_internet_config_proto_init() { return nil } } - file_transport_internet_config_proto_msgTypes[1].Exporter = func(v any, i int) any { + file_transport_internet_config_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*StreamConfig); i { case 0: return &v.state @@ -921,7 +921,7 @@ func file_transport_internet_config_proto_init() { return nil } } - file_transport_internet_config_proto_msgTypes[2].Exporter = func(v any, i int) any { + file_transport_internet_config_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ProxyConfig); i { case 0: return &v.state @@ -933,7 +933,7 @@ func file_transport_internet_config_proto_init() { return nil } } - file_transport_internet_config_proto_msgTypes[3].Exporter = func(v any, i int) any { + file_transport_internet_config_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*CustomSockopt); i { case 0: return &v.state @@ -945,7 +945,7 @@ func file_transport_internet_config_proto_init() { return nil } } - file_transport_internet_config_proto_msgTypes[4].Exporter = func(v any, i int) any { + file_transport_internet_config_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SocketConfig); i { case 0: return &v.state diff --git a/transport/internet/splithttp/config.pb.go b/transport/internet/splithttp/config.pb.go index adde71622133..8e69867e0a2f 100644 --- a/transport/internet/splithttp/config.pb.go +++ b/transport/internet/splithttp/config.pb.go @@ -31,6 +31,7 @@ type Config struct { MaxConcurrentUploads *RandRangeConfig `protobuf:"bytes,4,opt,name=maxConcurrentUploads,proto3" json:"maxConcurrentUploads,omitempty"` MaxUploadSize *RandRangeConfig `protobuf:"bytes,5,opt,name=maxUploadSize,proto3" json:"maxUploadSize,omitempty"` MinUploadIntervalMs *RandRangeConfig `protobuf:"bytes,6,opt,name=minUploadIntervalMs,proto3" json:"minUploadIntervalMs,omitempty"` + NoSSEHeader bool `protobuf:"varint,7,opt,name=noSSEHeader,proto3" json:"noSSEHeader,omitempty"` } func (x *Config) Reset() { @@ -107,6 +108,13 @@ func (x *Config) GetMinUploadIntervalMs() *RandRangeConfig { return nil } +func (x *Config) GetNoSSEHeader() bool { + if x != nil { + return x.NoSSEHeader + } + return false +} + type RandRangeConfig struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -169,8 +177,8 @@ var file_transport_internet_splithttp_config_proto_rawDesc = []byte{ 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x21, 0x78, 0x72, 0x61, 0x79, 0x2e, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x22, 0xe2, - 0x03, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, + 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x22, 0x84, + 0x04, 0x0a, 0x06, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x68, 0x6f, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x4d, 0x0a, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x03, 0x20, 0x03, 0x28, @@ -196,23 +204,25 @@ var file_transport_internet_splithttp_config_proto_rawDesc = []byte{ 0x2e, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x2e, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x13, 0x6d, 0x69, 0x6e, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x49, 0x6e, - 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, - 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, - 0x02, 0x38, 0x01, 0x22, 0x35, 0x0a, 0x0f, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e, 0x67, 0x65, - 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x74, 0x6f, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x74, 0x6f, 0x42, 0x85, 0x01, 0x0a, 0x25, 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, 0x73, 0x70, 0x6c, 0x69, 0x74, - 0x68, 0x74, 0x74, 0x70, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, - 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, 0x74, 0x65, - 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0xaa, 0x02, - 0x21, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2e, - 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53, 0x70, 0x6c, 0x69, 0x74, 0x48, 0x74, - 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x65, 0x72, 0x76, 0x61, 0x6c, 0x4d, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x6e, 0x6f, 0x53, 0x53, + 0x45, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x6e, + 0x6f, 0x53, 0x53, 0x45, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, + 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x35, 0x0a, 0x0f, 0x52, 0x61, 0x6e, 0x64, 0x52, 0x61, 0x6e, + 0x67, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x12, 0x0a, 0x04, 0x66, 0x72, 0x6f, 0x6d, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x66, 0x72, 0x6f, 0x6d, 0x12, 0x0e, 0x0a, 0x02, + 0x74, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x74, 0x6f, 0x42, 0x85, 0x01, 0x0a, + 0x25, 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, 0x73, 0x70, 0x6c, + 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, 0x50, 0x01, 0x5a, 0x36, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x74, 0x6c, 0x73, 0x2f, 0x78, 0x72, 0x61, 0x79, 0x2d, 0x63, + 0x6f, 0x72, 0x65, 0x2f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x2f, 0x69, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2f, 0x73, 0x70, 0x6c, 0x69, 0x74, 0x68, 0x74, 0x74, 0x70, + 0xaa, 0x02, 0x21, 0x58, 0x72, 0x61, 0x79, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, + 0x74, 0x2e, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x2e, 0x53, 0x70, 0x6c, 0x69, 0x74, + 0x48, 0x74, 0x74, 0x70, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/transport/internet/splithttp/config.proto b/transport/internet/splithttp/config.proto index 95381febd670..807732c3a766 100644 --- a/transport/internet/splithttp/config.proto +++ b/transport/internet/splithttp/config.proto @@ -13,6 +13,7 @@ message Config { RandRangeConfig maxConcurrentUploads = 4; RandRangeConfig maxUploadSize = 5; RandRangeConfig minUploadIntervalMs = 6; + bool noSSEHeader = 7; } message RandRangeConfig { diff --git a/transport/internet/splithttp/hub.go b/transport/internet/splithttp/hub.go index 86125504a204..ce54ed07b841 100644 --- a/transport/internet/splithttp/hub.go +++ b/transport/internet/splithttp/hub.go @@ -26,6 +26,7 @@ import ( ) type requestHandler struct { + config *Config host string path string ln *Listener @@ -182,8 +183,10 @@ func (h *requestHandler) ServeHTTP(writer http.ResponseWriter, request *http.Req // magic header instructs nginx + apache to not buffer response body writer.Header().Set("X-Accel-Buffering", "no") - // magic header to make the HTTP middle box consider this as SSE to disable buffer - writer.Header().Set("Content-Type", "text/event-stream") + if !h.config.NoSSEHeader { + // magic header to make the HTTP middle box consider this as SSE to disable buffer + writer.Header().Set("Content-Type", "text/event-stream") + } writer.WriteHeader(http.StatusOK) // send a chunk immediately to enable CDN streaming. @@ -267,6 +270,7 @@ func ListenSH(ctx context.Context, address net.Address, port net.Port, streamSet var err error var localAddr = gonet.TCPAddr{} handler := &requestHandler{ + config: shSettings, host: shSettings.Host, path: shSettings.GetNormalizedPath("", false), ln: l,