Skip to content

Commit

Permalink
fix(vmess): add h2c support for h2 and grpc transport (#209)
Browse files Browse the repository at this point in the history
* fix(vmess_: add h2c support for h2 and grpc transport

* Update clash_lib/src/proxy/vmess/mod.rs

Signed-off-by: Yuwei Ba <contact@yba.dev>

---------

Signed-off-by: Yuwei Ba <contact@yba.dev>
Co-authored-by: Yuwei Ba <contact@yba.dev>
  • Loading branch information
greenhat616 and ibigbug authored Dec 7, 2023
1 parent a30afa0 commit eeb2da3
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions clash_lib/src/proxy/vmess/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()],
Expand All @@ -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(),
Expand Down

0 comments on commit eeb2da3

Please sign in to comment.