@@ -74,7 +74,7 @@ pub fn validate_service_chaining_for_components(
7474 Ok ( ( ) )
7575}
7676
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.
7878#[ derive( Eq , Debug , Clone ) ]
7979pub struct AllowedHostConfig {
8080 original : String ,
@@ -113,24 +113,30 @@ impl AllowedHostConfig {
113113 } )
114114 }
115115
116+ /// Returns the scheme part of this config.
116117 pub fn scheme ( & self ) -> & SchemeConfig {
117118 & self . scheme
118119 }
119120
121+ /// Returns the host part of this config.
120122 pub fn host ( & self ) -> & HostConfig {
121123 & self . host
122124 }
123125
126+ /// Returns the port part of this config.
124127 pub fn port ( & self ) -> & PortConfig {
125128 & self . port
126129 }
127130
131+ /// Returns true if the given url is allowed by this config.
128132 fn allows ( & self , url : & OutboundUrl ) -> bool {
129133 self . scheme . allows ( & url. scheme )
130134 && self . host . allows ( & url. host )
131135 && self . port . allows ( url. port , & url. scheme )
132136 }
133137
138+ /// Returns true if this config allows relative ("self") requests to any of
139+ /// the given schemes.
134140 fn allows_relative ( & self , schemes : & [ & str ] ) -> bool {
135141 schemes. iter ( ) . any ( |s| self . scheme . allows ( s) ) && self . host . allows_relative ( )
136142 }
@@ -148,13 +154,17 @@ impl std::fmt::Display for AllowedHostConfig {
148154 }
149155}
150156
157+ /// Represents the scheme part of an allowed_outbound_hosts item.
151158#[ derive( PartialEq , Eq , Debug , Clone ) ]
152159pub enum SchemeConfig {
160+ /// Any scheme is allowed: `*://`
153161 Any ,
162+ /// Any of the given schemes are allowed
154163 List ( Vec < String > ) ,
155164}
156165
157166impl SchemeConfig {
167+ /// Parses the scheme part of an allowed_outbound_hosts item.
158168 fn parse ( scheme : & str ) -> anyhow:: Result < Self > {
159169 if scheme == "*" {
160170 return Ok ( Self :: Any ) ;
@@ -172,10 +182,12 @@ impl SchemeConfig {
172182 Ok ( Self :: List ( vec ! [ scheme. into( ) ] ) )
173183 }
174184
185+ /// Returns true if any scheme is allowed (i.e. `*://`).
175186 pub fn allows_any ( & self ) -> bool {
176187 matches ! ( self , Self :: Any )
177188 }
178189
190+ /// Returns true if the given scheme is allowed.
179191 fn allows ( & self , scheme : & str ) -> bool {
180192 match self {
181193 SchemeConfig :: Any => true ,
@@ -184,6 +196,7 @@ impl SchemeConfig {
184196 }
185197}
186198
199+ /// Represents the host part of an allowed_outbound_hosts item.
187200#[ derive( Debug , PartialEq , Eq , Clone ) ]
188201pub enum HostConfig {
189202 Any ,
@@ -194,6 +207,7 @@ pub enum HostConfig {
194207}
195208
196209impl HostConfig {
210+ /// Parses the host part of an allowed_outbound_hosts item.
197211 fn parse ( mut host : & str ) -> anyhow:: Result < Self > {
198212 host = host. trim ( ) ;
199213 if host == "*" {
@@ -234,6 +248,7 @@ impl HostConfig {
234248 Ok ( Self :: List ( vec ! [ host. into( ) ] ) )
235249 }
236250
251+ /// Returns true if the given host is allowed by this config.
237252 fn allows ( & self , host : & str ) -> bool {
238253 match self {
239254 HostConfig :: Any => true ,
@@ -249,6 +264,7 @@ impl HostConfig {
249264 }
250265 }
251266
267+ /// Returns true if this config allows relative ("self") requests.
252268 fn allows_relative ( & self ) -> bool {
253269 matches ! ( self , Self :: Any | Self :: ToSelf )
254270 }
@@ -261,6 +277,7 @@ pub enum PortConfig {
261277}
262278
263279impl PortConfig {
280+ /// Parses the port part of an allowed_outbound_hosts item.
264281 fn parse ( port : & str , scheme : & str ) -> anyhow:: Result < PortConfig > {
265282 if port. is_empty ( ) {
266283 return well_known_port ( scheme)
0 commit comments