@@ -5,7 +5,7 @@ use http::{header::HOST, Request};
5
5
use http_body_util:: BodyExt ;
6
6
use ip_network:: IpNetwork ;
7
7
use rustls:: ClientConfig ;
8
- use spin_factor_outbound_networking:: OutboundAllowedHosts ;
8
+ use spin_factor_outbound_networking:: { ComponentTlsConfigs , OutboundAllowedHosts } ;
9
9
use spin_factors:: { wasmtime:: component:: ResourceTable , RuntimeFactorsInstanceState } ;
10
10
use tokio:: { net:: TcpStream , time:: timeout} ;
11
11
use tracing:: { field:: Empty , instrument, Instrument } ;
@@ -19,7 +19,7 @@ use wasmtime_wasi_http::{
19
19
20
20
use crate :: {
21
21
wasi_2023_10_18, wasi_2023_11_10, InstanceState , InterceptOutcome , OutboundHttpFactor ,
22
- SelfRequestOrigin ,
22
+ OutboundHttpInterceptor , SelfRequestOrigin ,
23
23
} ;
24
24
25
25
pub ( crate ) fn add_to_linker < T : Send + ' static > (
@@ -84,46 +84,18 @@ impl<'a> WasiHttpView for WasiHttpImplInner<'a> {
84
84
) ]
85
85
fn send_request (
86
86
& mut self ,
87
- mut request : Request < wasmtime_wasi_http:: body:: HyperOutgoingBody > ,
88
- mut config : wasmtime_wasi_http:: types:: OutgoingRequestConfig ,
87
+ request : Request < wasmtime_wasi_http:: body:: HyperOutgoingBody > ,
88
+ config : wasmtime_wasi_http:: types:: OutgoingRequestConfig ,
89
89
) -> wasmtime_wasi_http:: HttpResult < wasmtime_wasi_http:: types:: HostFutureIncomingResponse > {
90
- // wasmtime-wasi-http fills in scheme and authority for relative URLs
91
- // (e.g. https://:443/<path>), which makes them hard to reason about.
92
- // Undo that here.
93
- let uri = request. uri_mut ( ) ;
94
- if uri
95
- . authority ( )
96
- . is_some_and ( |authority| authority. host ( ) . is_empty ( ) )
97
- {
98
- let mut builder = http:: uri:: Builder :: new ( ) ;
99
- if let Some ( paq) = uri. path_and_query ( ) {
100
- builder = builder. path_and_query ( paq. clone ( ) ) ;
101
- }
102
- * uri = builder. build ( ) . unwrap ( ) ;
103
- }
104
-
105
- if let Some ( interceptor) = & self . state . request_interceptor {
106
- match interceptor. intercept ( & mut request, & mut config) {
107
- InterceptOutcome :: Continue => ( ) ,
108
- InterceptOutcome :: Complete ( res) => return res,
109
- }
110
- }
111
-
112
- let host = request. uri ( ) . host ( ) . unwrap_or_default ( ) ;
113
- let tls_client_config = self
114
- . state
115
- . component_tls_configs
116
- . get_client_config ( host)
117
- . clone ( ) ;
118
-
119
90
Ok ( HostFutureIncomingResponse :: Pending (
120
91
wasmtime_wasi:: runtime:: spawn (
121
92
send_request_impl (
122
93
request,
123
94
config,
124
95
self . state . allowed_hosts . clone ( ) ,
96
+ self . state . component_tls_configs . clone ( ) ,
97
+ self . state . request_interceptor . clone ( ) ,
125
98
self . state . self_request_origin . clone ( ) ,
126
- tls_client_config,
127
99
self . state . allow_private_ips ,
128
100
)
129
101
. in_current_span ( ) ,
@@ -136,10 +108,36 @@ async fn send_request_impl(
136
108
mut request : Request < wasmtime_wasi_http:: body:: HyperOutgoingBody > ,
137
109
mut config : wasmtime_wasi_http:: types:: OutgoingRequestConfig ,
138
110
outbound_allowed_hosts : OutboundAllowedHosts ,
111
+ component_tls_configs : ComponentTlsConfigs ,
112
+ request_interceptor : Option < Arc < dyn OutboundHttpInterceptor > > ,
139
113
self_request_origin : Option < SelfRequestOrigin > ,
140
- tls_client_config : Arc < ClientConfig > ,
141
114
allow_private_ips : bool ,
142
115
) -> anyhow:: Result < Result < IncomingResponse , ErrorCode > > {
116
+ // wasmtime-wasi-http fills in scheme and authority for relative URLs
117
+ // (e.g. https://:443/<path>), which makes them hard to reason about.
118
+ // Undo that here.
119
+ let uri = request. uri_mut ( ) ;
120
+ if uri
121
+ . authority ( )
122
+ . is_some_and ( |authority| authority. host ( ) . is_empty ( ) )
123
+ {
124
+ let mut builder = http:: uri:: Builder :: new ( ) ;
125
+ if let Some ( paq) = uri. path_and_query ( ) {
126
+ builder = builder. path_and_query ( paq. clone ( ) ) ;
127
+ }
128
+ * uri = builder. build ( ) . unwrap ( ) ;
129
+ }
130
+
131
+ if let Some ( interceptor) = request_interceptor {
132
+ match interceptor. intercept ( & mut request, & mut config) . await ? {
133
+ InterceptOutcome :: Continue => ( ) ,
134
+ InterceptOutcome :: Complete ( resp) => return Ok ( Ok ( resp) ) ,
135
+ }
136
+ }
137
+
138
+ let host = request. uri ( ) . host ( ) . unwrap_or_default ( ) ;
139
+ let tls_client_config = component_tls_configs. get_client_config ( host) . clone ( ) ;
140
+
143
141
if request. uri ( ) . authority ( ) . is_some ( ) {
144
142
// Absolute URI
145
143
let is_allowed = outbound_allowed_hosts
0 commit comments