Skip to main content

builder

Function builder 

Source
pub fn builder<C, B, S, A>(
    client: Client<C, B>,
    scheme: S,
    authority: A,
) -> Result<Builder<C, B>, Error>
Available on crate features http1 or http2 only.
Expand description

Builder of ReusedService.

For the meaning of “scheme” and “authority”, refer to the documentation of Uri.

§Errors

When scheme or authority cannot be converted into a Scheme or Authority.

Examples found in repository?
examples/http2-proxy.rs (lines 56-62)
55    pub(super) async fn serve() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
56        let proxy_service_builder = builder(
57            Builder::new(hyper_util::rt::TokioExecutor::new())
58                .http2_only(true)
59                .build_http(),
60            Scheme::HTTP,
61            "127.0.0.1:3000",
62        )?;
63
64        let svc: tower_proxy::ReusedService<
65            tower_proxy::Identity,
66            tower_proxy::client::HttpConnector,
67            axum::body::Body,
68        > = proxy_service_builder.build(tower_proxy::rewrite::Identity {});
69
70        let router = Router::new().fallback_service(svc);
71
72        let listener = tokio::net::TcpListener::bind("127.0.0.1:2000")
73            .await
74            .unwrap();
75
76        axum::serve(listener, router).await?;
77
78        Ok(())
79    }