@@ -4,6 +4,7 @@ use url::Url;
4
4
use crate :: { errors:: AtomicResult , utils:: random_string} ;
5
5
6
6
pub enum Routes {
7
+ Agents ,
7
8
AllVersions ,
8
9
Collections ,
9
10
Commits ,
@@ -12,6 +13,7 @@ pub enum Routes {
12
13
Import ,
13
14
Tpf ,
14
15
Version ,
16
+ Setup ,
15
17
}
16
18
17
19
#[ derive( Debug , Clone , PartialEq , Eq ) ]
@@ -31,16 +33,18 @@ impl AtomicUrl {
31
33
}
32
34
33
35
/// Returns the route to some common Endpoint
34
- pub fn get_route ( & self , route : Routes ) -> Self {
36
+ pub fn set_route ( & self , route : Routes ) -> Self {
35
37
let path = match route {
36
38
Routes :: AllVersions => "/all-versions" . to_string ( ) ,
39
+ Routes :: Agents => "/agents" . to_string ( ) ,
37
40
Routes :: Collections => "/collections" . to_string ( ) ,
38
41
Routes :: Commits => "/commits" . to_string ( ) ,
39
42
Routes :: CommitsUnsigned => "/commits-unsigned" . to_string ( ) ,
40
43
Routes :: Endpoints => "/endpoints" . to_string ( ) ,
41
44
Routes :: Import => "/import" . to_string ( ) ,
42
45
Routes :: Tpf => "/tpf" . to_string ( ) ,
43
46
Routes :: Version => "/version" . to_string ( ) ,
47
+ Routes :: Setup => "/setup" . to_string ( ) ,
44
48
} ;
45
49
let mut new = self . url . clone ( ) ;
46
50
new. set_path ( & path) ;
@@ -68,25 +72,30 @@ impl AtomicUrl {
68
72
/// let start = "http://localhost";
69
73
/// let mut url = AtomicUrl::try_from(start).unwrap();
70
74
/// assert_eq!(url.to_string(), "http://localhost/");
75
+ /// url.append("/");
76
+ /// assert_eq!(url.to_string(), "http://localhost/");
71
77
/// url.append("someUrl/123");
72
78
/// assert_eq!(url.to_string(), "http://localhost/someUrl/123");
73
- /// url.append("345");
74
- /// assert_eq!(url.to_string(), "http://localhost/someUrl/123/345");
75
- /// url.append("/");
79
+ /// url.append("/345");
76
80
/// assert_eq!(url.to_string(), "http://localhost/someUrl/123/345");
77
81
/// ```
78
82
pub fn append ( & mut self , path : & str ) -> & Self {
79
- // Remove first slash if it exists
80
- let path = if path. starts_with ( '/' ) {
81
- if path . len ( ) == 1 {
82
- return self ;
83
+ let mut new_path = self . url . path ( ) . to_string ( ) ;
84
+ match ( new_path . ends_with ( '/' ) , path. starts_with ( '/' ) ) {
85
+ ( true , true ) => {
86
+ new_path . pop ( ) ;
83
87
}
84
- path. to_string ( )
85
- } else {
86
- format ! ( "/{path}" )
88
+ ( false , false ) => new_path. push ( '/' ) ,
89
+ _other => { }
87
90
} ;
88
- let mut new_path = self . url . path ( ) . to_string ( ) ;
89
- new_path. push_str ( & path) ;
91
+
92
+ // Remove first slash if it exists
93
+ if new_path. starts_with ( '/' ) {
94
+ new_path. remove ( 0 ) ;
95
+ }
96
+
97
+ new_path. push_str ( path) ;
98
+
90
99
self . url . set_path ( & new_path) ;
91
100
self
92
101
}
0 commit comments