11//! Implements the base structure (i.e. [WasiHttpCtx]) that will provide the
22//! implementation of the wasi-http API.
33
4- use crate :: io:: TokioIo ;
54use crate :: {
65 bindings:: http:: types:: { self , Method , Scheme } ,
76 body:: { HostIncomingBody , HyperIncomingBody , HyperOutgoingBody } ,
8- error:: dns_error,
9- hyper_request_error,
107} ;
118use anyhow:: bail;
129use bytes:: Bytes ;
@@ -15,12 +12,18 @@ use hyper::body::Body;
1512use hyper:: header:: HeaderName ;
1613use std:: any:: Any ;
1714use std:: time:: Duration ;
18- use tokio:: net:: TcpStream ;
19- use tokio:: time:: timeout;
2015use wasmtime:: component:: { Resource , ResourceTable } ;
2116use wasmtime_wasi:: p2:: { IoImpl , IoView , Pollable } ;
2217use wasmtime_wasi:: runtime:: AbortOnDropJoinHandle ;
2318
19+ #[ cfg( feature = "default-send-request" ) ]
20+ use {
21+ crate :: io:: TokioIo ,
22+ crate :: { error:: dns_error, hyper_request_error} ,
23+ tokio:: net:: TcpStream ,
24+ tokio:: time:: timeout,
25+ } ;
26+
2427/// Capture the state necessary for use in the wasi-http API implementation.
2528#[ derive( Debug ) ]
2629pub struct WasiHttpCtx {
@@ -117,7 +120,18 @@ pub trait WasiHttpView: IoView {
117120 request : hyper:: Request < HyperOutgoingBody > ,
118121 config : OutgoingRequestConfig ,
119122 ) -> crate :: HttpResult < HostFutureIncomingResponse > {
120- Ok ( default_send_request ( request, config) )
123+ #[ cfg( feature = "default-send-request" ) ]
124+ {
125+ Ok ( default_send_request ( request, config) )
126+ }
127+ #[ cfg( not( feature = "default-send-request" ) ) ]
128+ {
129+ let _ = ( request, config) ;
130+ Err ( crate :: bindings:: http:: types:: ErrorCode :: InternalError ( Some (
131+ "default-send-request feature disabled" . to_string ( ) ,
132+ ) )
133+ . into ( ) )
134+ }
121135 }
122136
123137 /// Whether a given header should be considered forbidden and not allowed.
@@ -317,6 +331,7 @@ pub struct OutgoingRequestConfig {
317331///
318332/// This implementation is used by the `wasi:http/outgoing-handler` interface
319333/// default implementation.
334+ #[ cfg( feature = "default-send-request" ) ]
320335pub fn default_send_request (
321336 request : hyper:: Request < HyperOutgoingBody > ,
322337 config : OutgoingRequestConfig ,
@@ -331,6 +346,7 @@ pub fn default_send_request(
331346/// in a task.
332347///
333348/// This is called from [default_send_request] to actually send the request.
349+ #[ cfg( feature = "default-send-request" ) ]
334350pub async fn default_send_request_handler (
335351 mut request : hyper:: Request < HyperOutgoingBody > ,
336352 OutgoingRequestConfig {
0 commit comments