seanmonstar / reqwest

An easy and powerful Rust HTTP Client
https://docs.rs/reqwest
Apache License 2.0
9.41k stars 1.05k forks source link

Skip DNS resolution to connect to IP. #2331

Open normalllll opened 6 days ago

normalllll commented 6 days ago

Can I skip DNS and use IP directly to access a domain name? I noticed this issue #561 mentioned DNS bypass.

Like this resolve does not working.

    let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 443);

    let client = reqwest::ClientBuilder::new().
        resolve("example.com", addr).
        tls_sni(false).
        use_rustls_tls().
        build().unwrap();

    client.request(reqwest::Method::GET, "https://example.com").send().await;
    ...
    ...

I saw this place using hyper::Request::builder, but it passed the uri argument directly. image

Then it returns the result for example.com instead of 127.0.0.1

<!doctype html>
<html>
<head>
    <title>Example Domain</title>

    <meta charset="utf-8" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <style type="text/css">
    body {
        background-color: #f0f0f2;
        margin: 0;
        padding: 0;
        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;

    }
    div {
        width: 600px;
        margin: 5em auto;
        padding: 2em;
        background-color: #fdfdff;
        border-radius: 0.5em;
        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
    }
    a:link, a:visited {
        color: #38488f;
        text-decoration: none;
    }
    @media (max-width: 700px) {
        div {
            margin: 0 auto;
            width: auto;
        }
    }
    </style>    
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.</p>
    <p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
seanmonstar commented 6 days ago

I'm not sure I understand. Does ClientBuilder::resolve(domain, ip) not work?

normalllll commented 5 days ago

Yes, he doesn't work.

The expected behavior is to send a request to 127.0.0.1, but in fact, it still requests example.com