@@ -308,11 +308,11 @@ impl<'a> Forwarded<'a> {
308
308
///
309
309
/// ```rust
310
310
/// let mut response = http_types::Response::new(200);
311
- /// http_types::proxies::Forwarded::new()
312
- /// .with_for(String::from( "192.0.2.43"))
313
- /// .with_for(String::from( "[2001:db8:cafe::17]"))
314
- /// .with_proto(String::from( "https"))
315
- /// .apply(&mut response);
311
+ /// let mut forwarded = http_types::proxies::Forwarded::new();
312
+ /// forwarded.add_for( "192.0.2.43");
313
+ /// forwarded.add_for( "[2001:db8:cafe::17]");
314
+ /// forwarded.set_proto( "https");
315
+ /// forwarded .apply(&mut response);
316
316
/// assert_eq!(response["Forwarded"], r#"for=192.0.2.43, for="[2001:db8:cafe::17]";proto=https"#);
317
317
/// ```
318
318
pub fn apply ( & self , mut headers : impl AsMut < Headers > ) {
@@ -325,10 +325,10 @@ impl<'a> Forwarded<'a> {
325
325
///
326
326
/// ```rust
327
327
/// # fn main() -> http_types::Result<()> {
328
- /// let forwarded = http_types::proxies::Forwarded::new()
329
- /// .with_for(String::from( "_haproxy"))
330
- /// .with_for(String::from( "[2001:db8:cafe::17]"))
331
- /// .with_proto(String::from( "https") );
328
+ /// let mut forwarded = http_types::proxies::Forwarded::new();
329
+ /// forwarded.add_for( "_haproxy");
330
+ /// forwarded.add_for( "[2001:db8:cafe::17]");
331
+ /// forwarded.set_proto( "https");
332
332
/// assert_eq!(forwarded.value()?, r#"for=_haproxy, for="[2001:db8:cafe::17]";proto=https"#);
333
333
/// # Ok(()) }
334
334
/// ```
@@ -368,63 +368,44 @@ impl<'a> Forwarded<'a> {
368
368
Self :: default ( )
369
369
}
370
370
371
- /// Returns the `by` field of this header
372
- pub fn by ( & self ) -> Option < & str > {
373
- self . by . as_deref ( )
371
+ /// Adds a `for` section to this header
372
+ pub fn add_for ( & mut self , forwarded_for : impl Into < Cow < ' a , str > > ) {
373
+ self . forwarded_for . push ( forwarded_for . into ( ) ) ;
374
374
}
375
375
376
376
/// Returns the `for` field of this header
377
377
pub fn forwarded_for ( & self ) -> Vec < & str > {
378
378
self . forwarded_for . iter ( ) . map ( |x| x. as_ref ( ) ) . collect ( )
379
379
}
380
380
381
+ /// Sets the `host` field of this header
382
+ pub fn set_host ( & mut self , host : impl Into < Cow < ' a , str > > ) {
383
+ self . host = Some ( host. into ( ) ) ;
384
+ }
385
+
381
386
/// Returns the `host` field of this header
382
387
pub fn host ( & self ) -> Option < & str > {
383
388
self . host . as_deref ( )
384
389
}
385
390
391
+ /// Sets the `proto` field of this header
392
+ pub fn set_proto ( & mut self , proto : impl Into < Cow < ' a , str > > ) {
393
+ self . proto = Some ( proto. into ( ) )
394
+ }
395
+
386
396
/// Returns the `proto` field of this header
387
397
pub fn proto ( & self ) -> Option < & str > {
388
398
self . proto . as_deref ( )
389
399
}
390
400
391
- /// sets the `host` field of this header
392
- pub fn set_host ( & mut self , host : String ) {
393
- self . host = Some ( Cow :: Owned ( host) ) ;
394
- }
395
-
396
- /// chainable builder for the `proto` field
397
- pub fn with_proto ( mut self , proto : String ) -> Self {
398
- self . proto = Some ( Cow :: Owned ( proto) ) ;
399
- self
400
- }
401
-
402
- /// adds a `for` section to this header
403
- pub fn add_for ( & mut self , forwarded_for : String ) {
404
- self . forwarded_for . push ( Cow :: Owned ( forwarded_for) ) ;
401
+ /// Sets the `by` field of this header
402
+ pub fn set_by ( & mut self , by : impl Into < Cow < ' a , str > > ) {
403
+ self . by = Some ( by. into ( ) ) ;
405
404
}
406
405
407
- /// chainable builder to add a `for` section to this header
408
- pub fn with_for ( mut self , forwarded_for : String ) -> Self {
409
- self . add_for ( forwarded_for) ;
410
- self
411
- }
412
-
413
- /// chainable builder set the `host` field of this header
414
- pub fn with_host ( mut self , host : String ) -> Self {
415
- self . set_host ( host) ;
416
- self
417
- }
418
-
419
- /// sets the `by` field of this header
420
- pub fn set_by ( & mut self , by : String ) {
421
- self . by = Some ( Cow :: Owned ( by) ) ;
422
- }
423
-
424
- /// chainable builder for the `by` field of this header
425
- pub fn with_by ( mut self , by : String ) -> Self {
426
- self . set_by ( by) ;
427
- self
406
+ /// Returns the `by` field of this header
407
+ pub fn by ( & self ) -> Option < & str > {
408
+ self . by . as_deref ( )
428
409
}
429
410
}
430
411
@@ -632,9 +613,9 @@ mod tests {
632
613
633
614
#[ test]
634
615
fn formatting_edge_cases ( ) -> Result < ( ) > {
635
- let forwarded = Forwarded :: new ( )
636
- . with_for ( r#"quote: " backslash: \"# . into ( ) )
637
- . with_for ( ";proto=https" . into ( ) ) ;
616
+ let mut forwarded = Forwarded :: new ( ) ;
617
+ forwarded . add_for ( r#"quote: " backslash: \"# ) ;
618
+ forwarded . add_for ( ";proto=https" ) ;
638
619
assert_eq ! (
639
620
forwarded. to_string( ) ,
640
621
r#"for="quote: \" backslash: \\", for=";proto=https""#
0 commit comments