@@ -3,6 +3,7 @@ use std::{net::SocketAddr, str, str::FromStr};
33use crate :: { Body , HttpExecutor , HttpTrigger , Store } ;
44use anyhow:: bail;
55use anyhow:: { anyhow, Context , Result } ;
6+ use http:: { HeaderName , HeaderValue } ;
67use http_body_util:: BodyExt ;
78use hyper:: { Request , Response } ;
89use outbound_http:: OutboundHttpComponent ;
@@ -42,7 +43,7 @@ impl HttpExecutor for HttpHandlerExecutor {
4243 set_http_origin_from_request ( & mut store, engine, & req) ;
4344
4445 let resp = match HandlerType :: from_exports ( instance. exports ( & mut store) ) {
45- Some ( HandlerType :: Wasi ) => Self :: execute_wasi ( store, instance, req) . await ?,
46+ Some ( HandlerType :: Wasi ) => Self :: execute_wasi ( store, instance, base , raw_route , req, client_addr ) . await ?,
4647 Some ( HandlerType :: Spin ) => {
4748 Self :: execute_spin ( store, instance, base, raw_route, req, client_addr)
4849 . await
@@ -68,11 +69,7 @@ impl HttpHandlerExecutor {
6869 req : Request < Body > ,
6970 client_addr : SocketAddr ,
7071 ) -> Result < Response < Body > > {
71- let headers;
72- let mut req = req;
73- {
74- headers = Self :: headers ( & mut req, raw_route, base, client_addr) ?;
75- }
72+ let headers = Self :: headers ( & req, raw_route, base, client_addr) ?;
7673 let func = instance
7774 . exports ( & mut store)
7875 . instance ( "fermyon:spin/inbound-http" )
@@ -147,8 +144,23 @@ impl HttpHandlerExecutor {
147144 async fn execute_wasi (
148145 mut store : Store ,
149146 instance : Instance ,
150- req : Request < Body > ,
147+ base : & str ,
148+ raw_route : & str ,
149+ mut req : Request < Body > ,
150+ client_addr : SocketAddr ,
151151 ) -> anyhow:: Result < Response < Body > > {
152+ let headers = Self :: headers ( & req, raw_route, base, client_addr) ?;
153+ req. headers_mut ( ) . clear ( ) ;
154+ req. headers_mut ( )
155+ . extend ( headers. into_iter ( ) . filter_map ( |( n, v) | {
156+ let Ok ( name) = n. parse :: < HeaderName > ( ) else {
157+ return None ;
158+ } ;
159+ let Ok ( value) = HeaderValue :: from_bytes ( v. as_bytes ( ) ) else {
160+ return None ;
161+ } ;
162+ Some ( ( name, value) )
163+ } ) ) ;
152164 let request = store. as_mut ( ) . data_mut ( ) . new_incoming_request ( req) ?;
153165
154166 let ( response_tx, response_rx) = oneshot:: channel ( ) ;
@@ -190,7 +202,7 @@ impl HttpHandlerExecutor {
190202 }
191203
192204 fn headers (
193- req : & mut Request < Body > ,
205+ req : & Request < Body > ,
194206 raw : & str ,
195207 base : & str ,
196208 client_addr : SocketAddr ,
@@ -280,6 +292,8 @@ fn set_http_origin_from_request(
280292 . get_or_insert ( outbound_http_handle) ;
281293
282294 outbound_http_data. origin = origin. clone ( ) ;
295+ store. as_mut ( ) . data_mut ( ) . as_mut ( ) . allowed_hosts =
296+ outbound_http_data. allowed_hosts . clone ( ) ;
283297 }
284298 store. as_mut ( ) . data_mut ( ) . as_mut ( ) . origin = Some ( origin) ;
285299 }
0 commit comments