Skip to main content

http_proxy

Function http_proxy 

Source
pub fn http_proxy<SV>(conf: &Arc<ServerConf>, inner: SV) -> HttpProxy<SV>
where SV: ProxyHttp,
Expand description

Create an HttpProxy without wrapping it in a Service.

This is useful when you need to integrate HttpProxy into a custom accept loop, for example when implementing SNI-based routing that decides between TLS passthrough and TLS termination on a single port.

The returned HttpProxy is fully initialized and ready to process requests via HttpServerApp::process_new_http().

§Example

use pingora_proxy::http_proxy;
use std::sync::Arc;

// Create the proxy
let proxy = Arc::new(http_proxy(&server_conf, my_proxy_app));

// In your custom accept loop:
loop {
    let (stream, addr) = listener.accept().await?;
     
    // Peek SNI, decide routing...
    if should_terminate_tls {
        let tls_stream = my_acceptor.accept(stream).await?;
        let session = HttpSession::new_http1(Box::new(tls_stream));
        proxy.process_new_http(session, &shutdown).await;
    }
}