@@ -3,15 +3,15 @@ use std::time::Duration;
33use anyhow:: bail;
44use http:: { Request , Uri } ;
55use spin_common:: { assert_matches, assert_not_matches} ;
6- use spin_factor_outbound_http:: { OutboundHttpFactor , SelfRequestOrigin } ;
6+ use spin_factor_outbound_http:: {
7+ ErrorCode , HostFutureIncomingResponse , OutboundHttpFactor , SelfRequestOrigin ,
8+ } ;
79use spin_factor_outbound_networking:: OutboundNetworkingFactor ;
810use spin_factor_variables:: VariablesFactor ;
911use spin_factors:: { anyhow, RuntimeFactors } ;
1012use spin_factors_test:: { toml, TestEnvironment } ;
1113use wasmtime_wasi:: p2:: Pollable ;
12- use wasmtime_wasi_http:: {
13- bindings:: http:: types:: ErrorCode , types:: OutgoingRequestConfig , WasiHttpView ,
14- } ;
14+ use wasmtime_wasi_http:: { types:: OutgoingRequestConfig , WasiHttpView } ;
1515
1616#[ derive( RuntimeFactors ) ]
1717struct TestFactors {
@@ -30,12 +30,7 @@ async fn allowed_host_is_allowed() -> anyhow::Result<()> {
3030 let mut future_resp = wasi_http. send_request ( req, test_request_config ( ) ) ?;
3131 future_resp. ready ( ) . await ;
3232
33- // Different systems handle the discard prefix differently; some will
34- // immediately reject it while others will silently let it time out
35- assert_matches ! (
36- future_resp. unwrap_ready( ) . unwrap( ) ,
37- Err ( ErrorCode :: ConnectionRefused | ErrorCode :: ConnectionTimeout ) ,
38- ) ;
33+ assert_discard_prefix_error ( future_resp) ;
3934 Ok ( ( ) )
4035}
4136
@@ -51,12 +46,7 @@ async fn self_request_smoke_test() -> anyhow::Result<()> {
5146 let mut future_resp = wasi_http. send_request ( req, test_request_config ( ) ) ?;
5247 future_resp. ready ( ) . await ;
5348
54- // Different systems handle the discard prefix differently; some will
55- // immediately reject it while others will silently let it time out
56- assert_matches ! (
57- future_resp. unwrap_ready( ) . unwrap( ) ,
58- Err ( ErrorCode :: ConnectionRefused | ErrorCode :: ConnectionTimeout ) ,
59- ) ;
49+ assert_discard_prefix_error ( future_resp) ;
6050 Ok ( ( ) )
6151}
6252
@@ -143,3 +133,15 @@ fn test_request_config() -> OutgoingRequestConfig {
143133 between_bytes_timeout : Duration :: from_millis ( 1 ) ,
144134 }
145135}
136+
137+ fn assert_discard_prefix_error ( future_resp : HostFutureIncomingResponse ) {
138+ // Different systems handle the discard prefix differently; some will
139+ // immediately reject it while others will silently let it time out
140+ assert_matches ! (
141+ future_resp. unwrap_ready( ) . unwrap( ) ,
142+ Err ( ErrorCode :: ConnectionRefused
143+ | ErrorCode :: ConnectionTimeout
144+ | ErrorCode :: ConnectionReadTimeout
145+ | ErrorCode :: DnsError ( _) ) ,
146+ ) ;
147+ }
0 commit comments