diff --git a/pingora-proxy/src/lib.rs b/pingora-proxy/src/lib.rs index b9f17d39..57b73fcc 100644 --- a/pingora-proxy/src/lib.rs +++ b/pingora-proxy/src/lib.rs @@ -1420,6 +1420,34 @@ where Service::new(name.to_string(), proxy) } +/// Create a [Service] from the user implemented [ProxyHttp] with h2c (cleartext HTTP/2) support. +/// +/// The returned [Service] can be hosted by a [pingora_core::server::Server] directly. +pub fn http_proxy_service_with_h2c( + conf: &Arc, + inner: SV, + name: &str, + enable_h2c: bool, +) -> Service> +where + SV: ProxyHttp, +{ + let mut proxy = HttpProxy::new(inner, conf.clone()); + proxy.handle_init_modules(); + + if enable_h2c { + use pingora_core::apps::HttpServerOptions; + use pingora_core::protocols::http::v2::server::H2Options; + + let mut opts = HttpServerOptions::default(); + opts.h2c = true; + proxy.server_options = Some(opts); + proxy.h2_options = Some(H2Options::default()); + } + + Service::new(name.to_string(), proxy) +} + /// Create a [Service] from the user implemented [ProxyHttp]. /// /// The returned [Service] can be hosted by a [pingora_core::server::Server] directly.