File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -284,11 +284,35 @@ impl<'a> Forwarded<'a> {
284
284
}
285
285
286
286
/// 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
+ /// ```
287
299
pub fn apply ( & self , mut headers : impl AsMut < Headers > ) {
288
300
headers. as_mut ( ) . insert ( FORWARDED , self ) ;
289
301
}
290
302
291
303
/// 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
+ /// ```
292
316
pub fn value ( & self ) -> Result < String , std:: fmt:: Error > {
293
317
let mut buf = String :: new ( ) ;
294
318
if let Some ( by) = self . by ( ) {
You can’t perform that action at this time.
0 commit comments