# Rust

> Rust reqwest 요청의 프록시와 인증서 처리를 설정해 HTTP/HTTPS 트래픽이 Proxyman에 표시되도록 합니다.

## 1. 문제 {#1-problem}

Rust의 `reqwest`는 다음 이유로 Proxyman이 HTTP/HTTPS 트래픽을 자동으로 캡처할 수 없습니다:

* `reqwest`는 시스템 HTTP 프록시를 따르지 않습니다 -> 트래픽이 Proxyman을 거치지 않습니다
* `reqwest`는 자체 서명된 Proxyman 인증서를 신뢰하지 않습니다 -> SSL 오류가 발생합니다

## 2. 해결 방법 {#2-solution}

* `http://localhost:9090`의 Proxyman으로 프록시를 직접 설정합니다
* SSL 검증을 비활성화합니다

```rust
use anyhow::Result;
use reqwest::Url;

#[tokio::main]
async fn main() -> Result<()> {
    let proxy_url = Url::parse("http://localhost:9090")?;
    let client = reqwest::Client::builder()
        .danger_accept_invalid_certs(true) // trust self-signed certificate
        .proxy(reqwest::Proxy::https(proxy_url)?) // Proxy to Proxyman
        .build()?;
    let response = client.get("https://httpbin.org/get").send().await?;

    if response.status().is_success() {
        let body = response.text().await?;
        println!("Response Text: {}", body);
    } else {
        println!("Request failed with status: {}", response.status());
    }

    Ok(())
}
```

> **노트:** 시스템 프록시를 무시하는 앱이라면 [Network Extension](https://proxyman.com/docs/ko/advanced-features/network-extension)(베타, macOS 26 이상)도 시도해 볼 수 있습니다. 이 기능은 앱마다 프록시를 설정하지 않고도 트래픽을 캡처합니다. HTTPS의 경우 Rust 클라이언트가 여전히 Proxyman 인증서를 신뢰하거나, 위에서 보여준 것처럼 검증을 건너뛰어야 합니다.
