Expand description
Provide proxy support for Savlo web framework.
§Example
In this example, if the requested URL begins with http://127.0.0.1:5800/, the proxy goes to https://www.rust-lang.org; if the requested URL begins with http://localhost:5800/, the proxy goes to https://www.rust-lang.org.
use salvo_core::prelude::*;
use salvo_proxy::Proxy;
#[tokio::main]
async fn main() {
let router = Router::new()
.push(
Router::new()
.host("127.0.0.1")
.path("<**rest>")
.goal(Proxy::use_hyper_client("https://www.rust-lang.org")),
)
.push(
Router::new()
.host("localhost")
.path("<**rest>")
.goal(Proxy::use_hyper_client("https://crates.io")),
);
let acceptor = TcpListener::new("0.0.0.0:5800").bind().await;
Server::new(acceptor).serve(router).await;
}
Structs§
- Hyper
Client hyper-client
AClient
implementation based onhyper_util::client::legacy::Client
. - Handler that can proxy request to other server.
- Reqwest
Client reqwest-client
AClient
implementation based onreqwest::Client
.
Traits§
- Client trait.
- Upstreams trait.
Functions§
- Default url path getter.
- Default url query getter. This getter just return the query string from request uri.
Type Aliases§
- Url part getter. You can use this to get the proxied url path or query.