71 个版本 (32 个破坏性版本)
新 0.71.1 | 2024 年 8 月 18 日 |
---|---|
0.70.0 | 2024 年 8 月 13 日 |
0.68.5 | 2024 年 7 月 9 日 |
0.66.2 | 2024 年 3 月 6 日 |
0.0.1 | 2022 年 10 月 10 日 |
在 HTTP 服务器 中排名 1344
每月下载量 2,333 次
在 3 个库中使用了它(通过 salvo)
665KB
15K SLoC
salvo-proxy
Salvo 的代理
这是一个官方库,因此您可以在 Cargo.toml
中像这样启用它
salvo = { version = "*", features=["proxy"] }
lib.rs
:
为 Savlo 网络框架提供代理支持。
示例
在这个示例中,如果请求的 URL 以 http://127.0.0.1:5800/ 开头,代理将转到 https://rust-lang.net.cn;如果请求的 URL 以 https://127.0.0.1:5800/ 开头,代理将转到 https://rust-lang.net.cn。
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://rust-lang.net.cn")),
)
.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;
}
依赖项
~19–35MB
~648K SLoC