File tree Expand file tree Collapse file tree 5 files changed +34
-2
lines changed
factor-outbound-networking/src
test-components/components/outbound-http/src
testcases/outbound-http-to-same-app Expand file tree Collapse file tree 5 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,12 @@ async fn send_request_impl(
152152 let host = request. uri ( ) . host ( ) . unwrap_or_default ( ) ;
153153 let tls_client_config = component_tls_configs. get_client_config ( host) . clone ( ) ;
154154
155- if request. uri ( ) . authority ( ) . is_some ( ) {
155+ let is_self_request = request
156+ . uri ( )
157+ . authority ( )
158+ . is_some_and ( |a| a. host ( ) == "self.alt" ) ;
159+
160+ if request. uri ( ) . authority ( ) . is_some ( ) && !is_self_request {
156161 // Absolute URI
157162 let is_allowed = outbound_allowed_hosts
158163 . check_url ( & request. uri ( ) . to_string ( ) , "https" )
Original file line number Diff line number Diff line change @@ -200,7 +200,7 @@ impl HostConfig {
200200 return Ok ( Self :: Any ) ;
201201 }
202202
203- if host == "self" {
203+ if host == "self" || host == "self.alt" {
204204 return Ok ( Self :: ToSelf ) ;
205205 }
206206
Original file line number Diff line number Diff line change @@ -372,6 +372,11 @@ mod integration_tests {
372372 Request :: new ( Method :: Get , "/outbound-allowed" ) ,
373373 Response :: new_with_body ( 200 , "Hello, Fermyon!\n " ) ,
374374 ) ?;
375+ assert_spin_request (
376+ spin,
377+ Request :: new ( Method :: Get , "/outbound-allowed-alt" ) ,
378+ Response :: new_with_body ( 200 , "Hello, Fermyon!\n " ) ,
379+ ) ?;
375380
376381 assert_spin_request (
377382 spin,
Original file line number Diff line number Diff line change @@ -7,14 +7,29 @@ use spin_sdk::{
77/// Send an HTTP request and return the response.
88#[ http_component]
99async fn send_outbound ( _req : Request ) -> Result < impl IntoResponse > {
10+ // Test self-request via relative URL
1011 let mut res: http:: Response < String > = spin_sdk:: http:: send (
1112 http:: Request :: builder ( )
1213 . method ( "GET" )
1314 . uri ( "/hello" )
1415 . body ( ( ) ) ?,
1516 )
1617 . await ?;
18+
19+ // Test self-request via self.alt
20+ let res_alt: http:: Response < String > = spin_sdk:: http:: send (
21+ http:: Request :: builder ( )
22+ . method ( "GET" )
23+ . uri ( "http://self.alt/hello" )
24+ . body ( ( ) ) ?,
25+ )
26+ . await ?;
27+
28+ assert_eq ! ( res. body( ) , res_alt. body( ) ) ;
29+ assert_eq ! ( res. status( ) , res_alt. status( ) ) ;
30+
1731 res. headers_mut ( )
1832 . insert ( "spin-component" , "outbound-http-component" . try_into ( ) ?) ;
33+
1934 Ok ( res)
2035}
Original file line number Diff line number Diff line change @@ -18,6 +18,13 @@ allowed_http_hosts = ["self"]
1818[component .trigger ]
1919route = " /outbound-allowed/..."
2020
21+ [[component ]]
22+ id = " outbound-http-allowed-alt"
23+ source = " %{source=outbound-http}"
24+ allowed_http_hosts = [" self.alt" ]
25+ [component .trigger ]
26+ route = " /outbound-allowed-alt/..."
27+
2128[[component ]]
2229id = " outbound-http-not-allowed"
2330source = " %{source=outbound-http}"
You can’t perform that action at this time.
0 commit comments