22 个版本 (5 个重大更新)
0.6.5 | 2024年4月2日 |
---|---|
0.6.4 | 2023年12月19日 |
0.5.2 | 2023年12月12日 |
0.4.7 | 2023年12月11日 |
0.1.1 | 2023年2月26日 |
#1719 in 网络编程
每月下载量 24
用于 synchronous-server
45KB
1.5K SLoC
proxy-server
低级别代理服务器。为了实现请求代理,仅使用了标准的 TcpStream
,而没有使用额外的库。
示例
使用默认参数
use proxy_server::Builder;
fn main() {
Builder::new().bind().expect("Error in proxy");
}
使用自定义参数
use proxy_server::{log::LogLevel, Builder};
fn main() {
Builder::new()
.with_address("127.0.0.1:3000")
.with_target("127.0.0.1:3001")
.with_log_level(LogLevel::Warn)
.with_threads(4)
.bind()
.expect("Error in proxy");
}
在每条请求中如果需要检查和更改目标
fn get_actual_target(old: &str) -> &'static str {
let target1 = "127.0.0.1:3001";
let target2 = "127.0.0.1:3003";
let res = match old {
"127.0.0.1:3001" => target2,
"127.0.0.1:3003" => target1,
_ => target1,
};
res
}
fn main() {
let cb: ChangeTarget = |old| get_actual_target(old);
Builder::new()
.bind(Some(cb))
.expect("Error in proxy");
}
版本控制
此包遵循语义版本控制(SemVer)方案。有关发布历史,请参阅变更日志。
依赖项
~2.5–9MB
~81K SLoC