From eeb2da3ab9e1a5ed0f78dd705a74690bdf8a4de5 Mon Sep 17 00:00:00 2001 From: Jonson Petard <41122242+greenhat616@users.noreply.github.com> Date: Thu, 7 Dec 2023 22:20:37 +0800 Subject: [PATCH] fix(vmess): add h2c support for h2 and grpc transport (#209) * fix(vmess_: add h2c support for h2 and grpc transport * Update clash_lib/src/proxy/vmess/mod.rs Signed-off-by: Yuwei Ba --------- Signed-off-by: Yuwei Ba Co-authored-by: Yuwei Ba --- clash_lib/src/proxy/vmess/mod.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/clash_lib/src/proxy/vmess/mod.rs b/clash_lib/src/proxy/vmess/mod.rs index 23402feaa..2ba51774e 100644 --- a/clash_lib/src/proxy/vmess/mod.rs +++ b/clash_lib/src/proxy/vmess/mod.rs @@ -83,14 +83,14 @@ impl Handler { ws_builder.proxy_stream(stream).await? } Some(VmessTransport::H2(ref opt)) => { - let mut tls_opt = self - .opts - .tls - .as_ref() - .expect("H2 conn must have tls opt") - .clone(); - tls_opt.alpn = Some(vec!["h2".to_string()]); - stream = transport::tls::wrap_stream(stream, tls_opt.to_owned(), None).await?; + stream = match self.opts.tls.as_ref() { + Some(tls_opt) => { + let mut tls_opt = tls_opt.clone(); + tls_opt.alpn = Some(vec!["h2".to_string()]); + transport::tls::wrap_stream(stream, tls_opt.to_owned(), None).await? + } + None => stream, + }; let h2_builder = Http2Config { hosts: vec![self.opts.server.clone()], @@ -102,9 +102,12 @@ impl Handler { h2_builder.proxy_stream(stream).await? } Some(VmessTransport::Grpc(ref opt)) => { - let tls_opt = self.opts.tls.as_ref().expect("gRPC conn must have tls opt"); - stream = - transport::tls::wrap_stream(stream, tls_opt.to_owned(), Some("h2")).await?; + stream = match self.opts.tls.as_ref() { + Some(tls_opt) => { + transport::tls::wrap_stream(stream, tls_opt.to_owned(), None).await? + } + None => stream, + }; let grpc_builder = transport::GrpcStreamBuilder::new( self.opts.server.clone(),