# reqwest_ss_proxy
---
## English
A `reqwest` middleware for proxying requests through a Shadowsocks server.
### Installation
```
reqwest_ss_proxy = "0.1.4"
anyhow = "1.0"
tokio = { version = "1", features = ["full"] }
reqwest = "0.12"
reqwest-middleware = "0.4"
```
### Usage
Here is an example of how to use `SsMiddleware` with `reqwest_middleware::ClientBuilder`, based on `tests/main.rs`.
```rust
use anyhow::Result;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_ss_proxy::{SsMiddleware, SsConnector};
#[tokio::main]
async fn main() -> Result<()> {
// 1. Create the SsConnector from your Shadowsocks URL.
// Replace with your Shadowsocks server URL.
let url = "ss://aes-256-gcm:password@server:port";
let connector = match SsConnector::new(url) {
Ok(c) => c,
Err(e) => {
panic!("Failed to create connector: {}", e);
}
};
// 2. Create the SsMiddleware from the connector.
let ss_middleware = SsMiddleware::new(connector);
// 3. Build the reqwest client with the middleware.
let client: ClientWithMiddleware =
ClientBuilder::new(reqwest::Client::new()).with(ss_middleware).build();
// 4. Send requests through the proxy.
for test_url in ["http://ifconfig.me/ip", "https://ifconfig.me/ip"] {
match client.get(test_url).send().await {
Ok(res) => {
let status = res.status();
let ip = res.text().await?;
println!("Request to {test_url}: Status={status}, IP={ip}");
}
Err(e) => {
eprintln!("Request to {test_url} failed: {e}");
}
}
}
Ok(())
}
```
---
## 中文
一个用于 `reqwest` 的 Shadowsocks 代理中间件。
### 安装
将此添加到您的 `Cargo.toml` 中:
```toml
[dependencies]
reqwest_ss_proxy = "0.1.4"
anyhow = "1.0"
tokio = { version = "1", features = ["full"] }
reqwest = "0.12"
reqwest-middleware = "0.4"
```
### 使用
这是一个如何将 `SsMiddleware` 与 `reqwest_middleware::ClientBuilder` 结合使用的示例,参考自 `tests/main.rs`。
```rust
use anyhow::Result;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_ss_proxy::{SsMiddleware, SsConnector};
#[tokio::main]
async fn main() -> Result<()> {
// 1. 从你的 Shadowsocks URL 创建 SsConnector。
// 请替换为你的 Shadowsocks 服务器 URL。
let url = "ss://aes-256-gcm:password@server:port";
let connector = match SsConnector::new(url) {
Ok(c) => c,
Err(e) => {
panic!("创建连接器失败: {}", e);
}
};
// 2. 从连接器创建 SsMiddleware。
let ss_middleware = SsMiddleware::new(connector);
// 3. 使用中间件构建 reqwest 客户端。
let client: ClientWithMiddleware =
ClientBuilder::new(reqwest::Client::new()).with(ss_middleware).build();
// 4. 通过代理发送请求。
for test_url in ["http://ifconfig.me/ip", "https://ifconfig.me/ip"] {
match client.get(test_url).send().await {
Ok(res) => {
let status = res.status();
let ip = res.text().await?;
println!("请求 {test_url}: Status={status}, IP={ip}");
}
Err(e) => {
eprintln!("请求 {test_url} 失败: {e}");
}
}
}
Ok(())
}
```
## About
This project is an open-source component of [i18n.site ⋅ Internationalization Solution](https://i18n.site).
* [i18 : MarkDown Command Line Translation Tool](https://i18n.site/i18)
The translation perfectly maintains the Markdown format.
It recognizes file changes and only translates the modified files.
The translated Markdown content is editable; if you modify the original text and translate it again, manually edited translations will not be overwritten (as long as the original text has not been changed).
* [i18n.site : MarkDown Multi-language Static Site Generator](https://i18n.site/i18n.site)
Optimized for a better reading experience
## 关于
本项目为 [i18n.site ⋅ 国际化解决方案](https://i18n.site) 的开源组件。
* [i18 : MarkDown 命令行翻译工具](https://i18n.site/i18)
翻译能够完美保持 Markdown 的格式。能识别文件的修改,仅翻译有变动的文件。
Markdown 翻译内容可编辑;如果你修改原文并再次机器翻译,手动修改过的翻译不会被覆盖 ( 如果这段原文没有被修改 )。
* [i18n.site : MarkDown 多语言静态站点生成器](https://i18n.site/i18n.site) 为阅读体验而优化。