@@ -10,11 +10,17 @@ use spin_factors::RuntimeFactors;
10
10
use spin_http:: routes:: RouteMatch ;
11
11
use tokio:: { sync:: oneshot, task} ;
12
12
use 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
+ } ;
14
17
15
18
use crate :: {
16
19
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
+ } ,
18
24
TriggerInstanceBuilder ,
19
25
} ;
20
26
@@ -65,47 +71,55 @@ impl HttpExecutor for WasiHttpExecutor {
65
71
drop ( wasi_http) ;
66
72
67
73
enum Handler {
68
- Latest ( Proxy ) ,
74
+ Latest ( IncomingHandler ) ,
69
75
Handler2023_11_10 ( IncomingHandler2023_11_10 ) ,
70
76
Handler2023_10_18 ( IncomingHandler2023_10_18 ) ,
71
77
}
72
78
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
79
85
. instance ( WASI_HTTP_EXPORT_2023_10_18 )
80
86
. ok_or_else ( || {
81
87
anyhow ! ( "export of `{WASI_HTTP_EXPORT_2023_10_18}` not an instance" )
82
88
} ) ?;
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
87
94
. instance ( WASI_HTTP_EXPORT_2023_11_10 )
88
95
. ok_or_else ( || {
89
96
anyhow ! ( "export of `{WASI_HTTP_EXPORT_2023_11_10}` not an instance" )
90
97
} ) ?;
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)
99
111
}
100
- } ;
112
+ HandlerType :: Spin => unreachable ! ( "should have used SpinHttpExecutor" ) ,
113
+ HandlerType :: Wagi => unreachable ! ( "should have used WagiExecutor instead" ) ,
114
+ }
115
+ } ;
101
116
102
117
let span = tracing:: debug_span!( "execute_wasi" ) ;
103
118
let handle = task:: spawn (
104
119
async move {
105
120
let result = match handler {
106
- Handler :: Latest ( proxy) => {
107
- proxy
108
- . wasi_http_incoming_handler ( )
121
+ Handler :: Latest ( handler) => {
122
+ handler
109
123
. call_handle ( & mut store, request, response)
110
124
. instrument ( span)
111
125
. await
0 commit comments