-
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathunix_socket.rs
More file actions
33 lines (28 loc) · 842 Bytes
/
Copy pathunix_socket.rs
File metadata and controls
33 lines (28 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#[cfg(unix)]
#[tokio::main]
async fn main() -> wreq::Result<()> {
// Create a Unix socket proxy
let proxy = wreq::Proxy::unix("/var/run/docker.sock")?;
// Build a client
let client = wreq::Client::builder()
// Specify the Unix socket path
.proxy(proxy.clone())
.timeout(std::time::Duration::from_secs(10))
.build()?;
// Use the API you're already familiar with
let resp = client
.get("http://localhost/v1.41/containers/json")
.send()
.await?;
println!("{}", resp.text().await?);
// Or specify the Unix socket directly in the request
let resp = client
.get("http://localhost/v1.41/containers/json")
.proxy(proxy)
.send()
.await?;
println!("{}", resp.text().await?);
Ok(())
}
#[cfg(not(unix))]
fn main() {}