File tree 1 file changed +20
-2
lines changed 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -507,13 +507,17 @@ impl Client {
507
507
508
508
/// Sets the base URL for this client. All request URLs will be relative to this URL.
509
509
///
510
+ /// Note: a trailing slash is significant.
511
+ /// Without it, the last path component is considered to be a “file” name
512
+ /// to be removed to get at the “directory” that is used as the base.
513
+ ///
510
514
/// # Examples
511
515
/// ```no_run
512
516
/// # use http_types::Url;
513
517
/// # fn main() -> http_types::Result<()> { async_std::task::block_on(async {
514
518
/// let mut client = surf::client();
515
- /// client.set_base_url(Url::parse("http://example.com/api/v1")?);
516
- /// client.get("/ posts.json").recv_json().await?; /// http://example.com/api/v1/posts.json
519
+ /// client.set_base_url(Url::parse("http://example.com/api/v1/ ")?);
520
+ /// client.get("posts.json").recv_json().await?; /// http://example.com/api/v1/posts.json
517
521
/// # Ok(()) }) }
518
522
/// ```
519
523
pub fn set_base_url ( & mut self , base : Url ) {
@@ -528,3 +532,17 @@ impl Client {
528
532
}
529
533
}
530
534
}
535
+
536
+ #[ cfg( test) ]
537
+ mod client_tests {
538
+ use super :: Client ;
539
+ use crate :: Url ;
540
+
541
+ #[ test]
542
+ fn base_url ( ) {
543
+ let mut client = Client :: new ( ) ;
544
+ client. set_base_url ( Url :: parse ( "http://example.com/api/v1/" ) . unwrap ( ) ) ;
545
+ let url = client. url ( "posts.json" ) ;
546
+ assert_eq ! ( url. as_str( ) , "http://example.com/api/v1/posts.json" ) ;
547
+ }
548
+ }
You can’t perform that action at this time.
0 commit comments