wasmer_wasix/runners/
mod.rs

1mod runner;
2
3#[cfg(feature = "webc_runner_rt_dcgi")]
4pub mod dcgi;
5#[cfg(feature = "webc_runner_rt_dproxy")]
6pub mod dproxy;
7pub mod wasi;
8mod wasi_common;
9#[cfg(feature = "webc_runner_rt_wcgi")]
10pub mod wcgi;
11
12#[cfg(any(feature = "webc_runner_rt_wcgi", feature = "webc_runner_rt_dproxy"))]
13mod body {
14    use http_body_util::{BodyExt, Full, combinators::BoxBody};
15
16    pub type Body = BoxBody<bytes::Bytes, anyhow::Error>;
17
18    pub fn body_from_data(data: impl Into<bytes::Bytes>) -> Body {
19        BoxBody::new(Full::new(data.into()).map_err(|_| -> anyhow::Error { unreachable!() }))
20    }
21
22    pub fn body_from_stream<S>(s: S) -> Body
23    where
24        S: futures::stream::Stream<Item = Result<hyper::body::Frame<bytes::Bytes>, anyhow::Error>>
25            + Send
26            + Sync
27            + 'static,
28    {
29        BoxBody::new(http_body_util::StreamBody::new(s))
30    }
31}
32
33#[cfg(any(feature = "webc_runner_rt_wcgi", feature = "webc_runner_rt_dproxy"))]
34pub use self::body::*;
35
36pub use self::{
37    runner::Runner,
38    wasi_common::{
39        ExistingMountConflictBehavior, MAPPED_CURRENT_DIR_DEFAULT_PATH, MappedCommand,
40        MappedDirectory, MountedDirectory,
41    },
42};
43
44// For some reason, providing the same code to on_response() in a lambda
45// causes lifetime-related errors, so we use an owned struct instead to
46// make *absolutely* sure it's 'static.
47#[cfg(any(feature = "webc_runner_rt_wcgi", feature = "webc_runner_rt_dproxy"))]
48mod response_tracing {
49    use tower_http::trace::OnResponse;
50
51    #[derive(Clone, Copy)]
52    pub struct OnResponseTracer;
53
54    impl<B> OnResponse<B> for OnResponseTracer {
55        fn on_response(
56            self,
57            response: &http::Response<B>,
58            _latency: std::time::Duration,
59            span: &tracing::Span,
60        ) {
61            span.record("status_code", tracing::field::display(response.status()));
62            tracing::info!("response generated")
63        }
64    }
65}