@@ -10,11 +10,17 @@ use spin_factors::RuntimeFactors;
1010use spin_http:: routes:: RouteMatch ;
1111use tokio:: { sync:: oneshot, task} ;
1212use tracing:: { instrument, Instrument , Level } ;
13- use wasmtime_wasi_http:: { body:: HyperIncomingBody as Body , proxy:: Proxy , WasiHttpView } ;
13+ use wasmtime_wasi_http:: {
14+ body:: HyperIncomingBody as Body ,
15+ proxy:: exports:: wasi:: http:: incoming_handler:: Guest as IncomingHandler , WasiHttpView ,
16+ } ;
1417
1518use crate :: {
1619 headers:: prepare_request_headers,
17- server:: { HandlerType , HttpExecutor , WASI_HTTP_EXPORT_2023_10_18 , WASI_HTTP_EXPORT_2023_11_10 } ,
20+ server:: {
21+ HandlerType , HttpExecutor , WASI_HTTP_EXPORT_0_2_0 , WASI_HTTP_EXPORT_0_2_1 ,
22+ WASI_HTTP_EXPORT_2023_10_18 , WASI_HTTP_EXPORT_2023_11_10 ,
23+ } ,
1824 TriggerInstanceBuilder ,
1925} ;
2026
@@ -65,47 +71,55 @@ impl HttpExecutor for WasiHttpExecutor {
6571 drop ( wasi_http) ;
6672
6773 enum Handler {
68- Latest ( Proxy ) ,
74+ Latest ( IncomingHandler ) ,
6975 Handler2023_11_10 ( IncomingHandler2023_11_10 ) ,
7076 Handler2023_10_18 ( IncomingHandler2023_10_18 ) ,
7177 }
7278
73- let handler =
74- {
75- let mut exports = instance . exports ( & mut store ) ;
76- match self . handler_type {
77- HandlerType :: Wasi2023_10_18 => {
78- let mut instance = exports
79+ let handler = {
80+ let mut exports = instance . exports ( & mut store ) ;
81+ match self . handler_type {
82+ HandlerType :: Wasi2023_10_18 => {
83+ let mut instance =
84+ exports
7985 . instance ( WASI_HTTP_EXPORT_2023_10_18 )
8086 . ok_or_else ( || {
8187 anyhow ! ( "export of `{WASI_HTTP_EXPORT_2023_10_18}` not an instance" )
8288 } ) ?;
83- Handler :: Handler2023_10_18 ( IncomingHandler2023_10_18 :: new ( & mut instance) ?)
84- }
85- HandlerType :: Wasi2023_11_10 => {
86- let mut instance = exports
89+ Handler :: Handler2023_10_18 ( IncomingHandler2023_10_18 :: new ( & mut instance) ?)
90+ }
91+ HandlerType :: Wasi2023_11_10 => {
92+ let mut instance =
93+ exports
8794 . instance ( WASI_HTTP_EXPORT_2023_11_10 )
8895 . ok_or_else ( || {
8996 anyhow ! ( "export of `{WASI_HTTP_EXPORT_2023_11_10}` not an instance" )
9097 } ) ?;
91- Handler :: Handler2023_11_10 ( IncomingHandler2023_11_10 :: new ( & mut instance) ?)
92- }
93- HandlerType :: Wasi0_2 => {
94- drop ( exports) ;
95- Handler :: Latest ( Proxy :: new ( & mut store, & instance) ?)
96- }
97- HandlerType :: Spin => unreachable ! ( "should have used SpinHttpExecutor" ) ,
98- HandlerType :: Wagi => unreachable ! ( "should have used WagiExecutor instead" ) ,
98+ Handler :: Handler2023_11_10 ( IncomingHandler2023_11_10 :: new ( & mut instance) ?)
99+ }
100+ HandlerType :: Wasi0_2 => {
101+ let handler = if let Some ( mut export) = exports. instance ( WASI_HTTP_EXPORT_0_2_1 )
102+ {
103+ IncomingHandler :: new ( & mut export)
104+ } else if let Some ( mut export) = exports. instance ( WASI_HTTP_EXPORT_0_2_0 ) {
105+ IncomingHandler :: new ( & mut export)
106+ } else {
107+ Err ( anyhow ! ( "export of `{WASI_HTTP_EXPORT_0_2_0}` or `{WASI_HTTP_EXPORT_0_2_1}` not an instance" ) )
108+ } ?;
109+
110+ Handler :: Latest ( handler)
99111 }
100- } ;
112+ HandlerType :: Spin => unreachable ! ( "should have used SpinHttpExecutor" ) ,
113+ HandlerType :: Wagi => unreachable ! ( "should have used WagiExecutor instead" ) ,
114+ }
115+ } ;
101116
102117 let span = tracing:: debug_span!( "execute_wasi" ) ;
103118 let handle = task:: spawn (
104119 async move {
105120 let result = match handler {
106- Handler :: Latest ( proxy) => {
107- proxy
108- . wasi_http_incoming_handler ( )
121+ Handler :: Latest ( handler) => {
122+ handler
109123 . call_handle ( & mut store, request, response)
110124 . instrument ( span)
111125 . await
0 commit comments