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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! # http-unix-client
//!
//! An HTTP client for interacting with HTTP servers over Unix sockets.
//! The crate mimics the architecture of the [reqwest](https://docs.rs/reqwest/latest/reqwest/) crate.
//! The [`Client`] is asynchronous (requiring Tokio).
//!
//! ## Supported Platforms
//!
//! This crate is only supported on Unix-like systems (Linux, macOS, BSD, etc.) because it relies on Unix domain sockets.
//!
//! ## Examples
//!
//! ### Making a GET request
//!
//! For a single request, you can use the [`get`] shortcut method.
//!
//! ```rust
//! # use http_unix_client::{Client, Error, get};
//! #
//! # async fn run() -> Result<(), Error> {
//! let body = get("/tmp/my.socket", "/health")
//! .await?
//! .text()
//! .await?;
//!
//! println!("body = {body:?}");
//! # Ok(())
//! # }
//! ```
//!
//! **NOTE**: If you plan to perform multiple requests, it is best to create a
//! [`Client`] and reuse it, taking advantage of keep-alive connection
//! pooling.
//!
//! ## Making POST requests (or setting request bodies)
//!
//! There are several ways you can set the body of a request. The basic one is
//! by using the `body()` method of a [`RequestBuilder`]. This lets you set the
//! exact raw bytes of what the body should be. It accepts various types,
//! including `String` and `Vec<u8>`. If you wish to pass a custom
//! type, you can use the `reqwest::Body` constructors.
//!
//! ```rust
//! # use http_unix_client::{Client, Error};
//!
//! # async fn run() -> Result<(), Error> {
//! let client = Client::new();
//! let res = client.post("/tmp/my.socket", "/health")
//! .body("the exact body that is sent")
//! .send()
//! .await?;
//! # Ok(())
//! # }
//! ```
//!
//! ### Forms
//!
//! It's very common to want to send form data in a request body. This can be
//! done with any type that can be serialized into form data.
//!
//! This can be an array of tuples, or a `HashMap`, or a custom type that
//! implements [`Serialize`][serde].
//!
//! ```no_run
//! # use http_unix_client::{Client, Error};
//! #
//! # async fn run() -> Result<(), Error> {
//! // This will POST a body of `foo=bar&baz=quux`
//! let params = [("foo", "bar"), ("baz", "quux")];
//! let client = Client::new();
//! let res = client.post("/tmp/my.socket", "/health")
//! .form(¶ms)
//! .send()
//! .await?;
//! Ok(())
//! }
//! ```
//!
//! ### JSON
//!
//! There is also a `json` method helper on the [`RequestBuilder`] that works in
//! a similar fashion the `form` method. It can take any value that can be
//! serialized into JSON. The feature `json` is required.
//!
//! ```rust
//! # use http_unix_client::{Client, Error};
//! # use std::collections::HashMap;
//! #
//! # #[cfg(feature = "json")]
//! # async fn run() -> Result<(), Error> {
//! // This will POST a body of `{"lang":"rust","body":"json"}`
//! let mut map = HashMap::new();
//! map.insert("lang", "rust");
//! map.insert("body", "json");
//! let client = Client::new();
//! let res = client.post("/tmp/my.socket", "/health")
//! .json(&map)
//! .send()
//! .await?;
//! # Ok(())
//! # }
//! ```
pub use Body;
pub use Client;
pub use Cookie;
pub use ;
pub use ;
pub use ;
pub use Response;
pub use UnixUrl;
pub use Url;
/// Shortcut method to quickly make a `GET` request.
///
/// See also the methods on the [`Response`]
/// type.
///
/// **NOTE**: This function creates a new internal `Client` on each call,
/// and so should not be used if making many requests. Create a
/// [`Client`] instead.
///
/// # Examples
///
/// ```rust
/// # use http_unix_client::Error;
///
/// # async fn run() -> Result<(), Error> {
/// let body = http_unix_client::get("/tmp/my.socket", "/").await?
/// .text().await?;
/// # Ok(())
/// # }
/// ```
///
/// # Errors
///
/// This function fails if:
///
/// - supplied `path` cannot be parsed to an url
/// - there was an error while sending request
pub async