rust-proxy 0.1.0

A simple HTTP/HTTPS proxy server written in Rust
use hyper::{body::HttpBody, Client};
use hyper::client::HttpConnector;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // 创建HTTP客户端
    let client: Client<HttpConnector> = Client::new();

    // 通过代理访问目标网站
    let uri = "http://httpbin.org/get".parse()?;

    println!("通过代理发送请求到: {}", uri);

    let mut res = client.get(uri).await?;

    println!("响应状态: {}", res.status());
    println!("响应头:");
    for (name, value) in res.headers() {
        println!("  {}: {}", name, value.to_str().unwrap_or("[binary]"));
    }

    // 读取响应体
    let mut body = String::new();
    while let Some(chunk) = res.body_mut().data().await {
        let chunk = chunk?;
        body.push_str(&String::from_utf8_lossy(&chunk));
    }

    println!("响应体长度: {} 字节", body.len());
    println!("响应体内容:");
    println!("{}", body);

    Ok(())
}