Skip to content

Commit 5829a78

Browse files
committed
add an example for apply and value
1 parent 02bb120 commit 5829a78

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/proxies/forwarded.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,35 @@ impl<'a> Forwarded<'a> {
284284
}
285285

286286
/// Insert a header that represents this Forwarded.
287+
///
288+
/// # Example
289+
///
290+
/// ```rust
291+
/// let mut response = http_types::Response::new(200);
292+
/// http_types::proxies::Forwarded::new()
293+
/// .with_for(String::from("192.0.2.43"))
294+
/// .with_for(String::from("[2001:db8:cafe::17]"))
295+
/// .with_proto(String::from("https"))
296+
/// .apply(&mut response);
297+
/// assert_eq!(response["Forwarded"], r#"for=192.0.2.43, for="[2001:db8:cafe::17]";proto=https"#);
298+
/// ```
287299
pub fn apply(&self, mut headers: impl AsMut<Headers>) {
288300
headers.as_mut().insert(FORWARDED, self);
289301
}
290302

291303
/// Builds a Forwarded header as a String.
304+
///
305+
/// # Example
306+
///
307+
/// ```rust
308+
/// # fn main() -> http_types::Result<()> {
309+
/// let forwarded = http_types::proxies::Forwarded::new()
310+
/// .with_for(String::from("_haproxy"))
311+
/// .with_for(String::from("[2001:db8:cafe::17]"))
312+
/// .with_proto(String::from("https"));
313+
/// assert_eq!(forwarded.value()?, r#"for=_haproxy, for="[2001:db8:cafe::17]";proto=https"#);
314+
/// # Ok(()) }
315+
/// ```
292316
pub fn value(&self) -> Result<String, std::fmt::Error> {
293317
let mut buf = String::new();
294318
if let Some(by) = self.by() {

0 commit comments

Comments
 (0)