@@ -74,7 +74,7 @@ pub fn validate_service_chaining_for_components(
74
74
Ok ( ( ) )
75
75
}
76
76
77
- /// An address is a url-like string that contains a host, a port, and an optional scheme
77
+ /// Represents a single `allowed_outbound_hosts` item.
78
78
#[ derive( Eq , Debug , Clone ) ]
79
79
pub struct AllowedHostConfig {
80
80
original : String ,
@@ -113,24 +113,30 @@ impl AllowedHostConfig {
113
113
} )
114
114
}
115
115
116
+ /// Returns the scheme part of this config.
116
117
pub fn scheme ( & self ) -> & SchemeConfig {
117
118
& self . scheme
118
119
}
119
120
121
+ /// Returns the host part of this config.
120
122
pub fn host ( & self ) -> & HostConfig {
121
123
& self . host
122
124
}
123
125
126
+ /// Returns the port part of this config.
124
127
pub fn port ( & self ) -> & PortConfig {
125
128
& self . port
126
129
}
127
130
131
+ /// Returns true if the given url is allowed by this config.
128
132
fn allows ( & self , url : & OutboundUrl ) -> bool {
129
133
self . scheme . allows ( & url. scheme )
130
134
&& self . host . allows ( & url. host )
131
135
&& self . port . allows ( url. port , & url. scheme )
132
136
}
133
137
138
+ /// Returns true if this config allows relative ("self") requests to any of
139
+ /// the given schemes.
134
140
fn allows_relative ( & self , schemes : & [ & str ] ) -> bool {
135
141
schemes. iter ( ) . any ( |s| self . scheme . allows ( s) ) && self . host . allows_relative ( )
136
142
}
@@ -148,13 +154,17 @@ impl std::fmt::Display for AllowedHostConfig {
148
154
}
149
155
}
150
156
157
+ /// Represents the scheme part of an allowed_outbound_hosts item.
151
158
#[ derive( PartialEq , Eq , Debug , Clone ) ]
152
159
pub enum SchemeConfig {
160
+ /// Any scheme is allowed: `*://`
153
161
Any ,
162
+ /// Any of the given schemes are allowed
154
163
List ( Vec < String > ) ,
155
164
}
156
165
157
166
impl SchemeConfig {
167
+ /// Parses the scheme part of an allowed_outbound_hosts item.
158
168
fn parse ( scheme : & str ) -> anyhow:: Result < Self > {
159
169
if scheme == "*" {
160
170
return Ok ( Self :: Any ) ;
@@ -172,10 +182,12 @@ impl SchemeConfig {
172
182
Ok ( Self :: List ( vec ! [ scheme. into( ) ] ) )
173
183
}
174
184
185
+ /// Returns true if any scheme is allowed (i.e. `*://`).
175
186
pub fn allows_any ( & self ) -> bool {
176
187
matches ! ( self , Self :: Any )
177
188
}
178
189
190
+ /// Returns true if the given scheme is allowed.
179
191
fn allows ( & self , scheme : & str ) -> bool {
180
192
match self {
181
193
SchemeConfig :: Any => true ,
@@ -184,6 +196,7 @@ impl SchemeConfig {
184
196
}
185
197
}
186
198
199
+ /// Represents the host part of an allowed_outbound_hosts item.
187
200
#[ derive( Debug , PartialEq , Eq , Clone ) ]
188
201
pub enum HostConfig {
189
202
Any ,
@@ -194,6 +207,7 @@ pub enum HostConfig {
194
207
}
195
208
196
209
impl HostConfig {
210
+ /// Parses the host part of an allowed_outbound_hosts item.
197
211
fn parse ( mut host : & str ) -> anyhow:: Result < Self > {
198
212
host = host. trim ( ) ;
199
213
if host == "*" {
@@ -234,6 +248,7 @@ impl HostConfig {
234
248
Ok ( Self :: List ( vec ! [ host. into( ) ] ) )
235
249
}
236
250
251
+ /// Returns true if the given host is allowed by this config.
237
252
fn allows ( & self , host : & str ) -> bool {
238
253
match self {
239
254
HostConfig :: Any => true ,
@@ -249,6 +264,7 @@ impl HostConfig {
249
264
}
250
265
}
251
266
267
+ /// Returns true if this config allows relative ("self") requests.
252
268
fn allows_relative ( & self ) -> bool {
253
269
matches ! ( self , Self :: Any | Self :: ToSelf )
254
270
}
@@ -261,6 +277,7 @@ pub enum PortConfig {
261
277
}
262
278
263
279
impl PortConfig {
280
+ /// Parses the port part of an allowed_outbound_hosts item.
264
281
fn parse ( port : & str , scheme : & str ) -> anyhow:: Result < PortConfig > {
265
282
if port. is_empty ( ) {
266
283
return well_known_port ( scheme)
0 commit comments