pub struct ExecuteCtx { /* private fields */ }Expand description
Execution context used by a ViceroyService.
This is all of the state needed to instantiate a module, in order to respond to an HTTP
request. Note that it is very important that ExecuteCtx be cheaply clonable, as it is cloned
every time that a viceroy service handles an incoming connection.
Implementations§
Source§impl ExecuteCtx
impl ExecuteCtx
Sourcepub fn build(
module_path: impl AsRef<Path>,
profiling_strategy: ProfilingStrategy,
wasi_modules: HashSet<ExperimentalModule>,
guest_profile_config: Option<GuestProfileConfig>,
unknown_import_behavior: UnknownImportBehavior,
adapt_components: bool,
) -> Result<ExecuteCtxBuilder, Error>
pub fn build( module_path: impl AsRef<Path>, profiling_strategy: ProfilingStrategy, wasi_modules: HashSet<ExperimentalModule>, guest_profile_config: Option<GuestProfileConfig>, unknown_import_behavior: UnknownImportBehavior, adapt_components: bool, ) -> Result<ExecuteCtxBuilder, Error>
Build a new execution context, given the path to a module and a set of experimental wasi modules.
Sourcepub fn new(
module_path: impl AsRef<Path>,
profiling_strategy: ProfilingStrategy,
wasi_modules: HashSet<ExperimentalModule>,
guest_profile_config: Option<GuestProfileConfig>,
unknown_import_behavior: UnknownImportBehavior,
adapt_components: bool,
) -> Result<Arc<Self>, Error>
pub fn new( module_path: impl AsRef<Path>, profiling_strategy: ProfilingStrategy, wasi_modules: HashSet<ExperimentalModule>, guest_profile_config: Option<GuestProfileConfig>, unknown_import_behavior: UnknownImportBehavior, adapt_components: bool, ) -> Result<Arc<Self>, Error>
Create a new execution context, given the path to a module and a set of experimental wasi modules.
Sourcepub fn device_detection(&self) -> &DeviceDetection
pub fn device_detection(&self) -> &DeviceDetection
Get the device detection mappings for this execution context.
Sourcepub fn geolocation(&self) -> &Geolocation
pub fn geolocation(&self) -> &Geolocation
Get the geolocation mappings for this execution context.
Sourcepub fn dictionaries(&self) -> &Dictionaries
pub fn dictionaries(&self) -> &Dictionaries
Get the dictionaries for this execution context.
Sourcepub fn capture_logs(&self) -> Arc<Mutex<dyn Write + Send>>
pub fn capture_logs(&self) -> Arc<Mutex<dyn Write + Send>>
Where to direct logging endpoint messages. Defaults to stdout.
Sourcepub fn log_stdout(&self) -> bool
pub fn log_stdout(&self) -> bool
Whether to treat stdout as a logging endpoint.
Sourcepub fn log_stderr(&self) -> bool
pub fn log_stderr(&self) -> bool
Whether to treat stderr as a logging endpoint.
Sourcepub fn tls_config(&self) -> &TlsConfig
pub fn tls_config(&self) -> &TlsConfig
Gets the TLS configuration
Sourcepub async fn handle_request(
self: Arc<Self>,
incoming_req: Request<Body>,
local: SocketAddr,
remote: SocketAddr,
) -> Result<(Response<Body>, Option<Error>), Error>
pub async fn handle_request( self: Arc<Self>, incoming_req: Request<Body>, local: SocketAddr, remote: SocketAddr, ) -> Result<(Response<Body>, Option<Error>), Error>
Asynchronously handle a request.
This method fully instantiates the wasm module housed within the ExecuteCtx,
including running the wasm start function. It then proceeds to execute the
instantiated module’s WASI entry point, running to completion. If execution
results in an error, a response is still produced, but with a 500 status code.
Build time: Before you build or test your code, we recommend to set the release flag
e.g. cargo test --release otherwise the execution will be very slow. This has to do
with the Cranelift compiler, which is extremely slow when compiled in debug mode.
§Example
use hyper::{Body, http::Request};
let adapt_core_wasm = false;
let ctx = ExecuteCtx::new("path/to/a/file.wasm", ProfilingStrategy::None, HashSet::new(), None, Default::default(), adapt_core_wasm)?;
let local = "127.0.0.1:80".parse().unwrap();
let remote = "127.0.0.1:0".parse().unwrap();
let resp = ctx.handle_request(req, local, remote).await?;pub async fn handle_request_with_runtime_error( self: Arc<Self>, incoming_req: Request<Body>, local: SocketAddr, remote: SocketAddr, ) -> Result<Response<Body>, Error>
pub async fn run_main( self: Arc<Self>, program_name: &str, args: &[String], ) -> Result<(), Error>
pub fn cache(&self) -> &Arc<Cache>
pub fn config_path(&self) -> Option<&Path>
pub fn object_store(&self) -> &ObjectStores
pub fn secret_stores(&self) -> &SecretStores
pub fn shielding_sites(&self) -> &ShieldingSites
pub async fn register_pending_downstream(&self) -> Option<Receiver<NextRequest>>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ExecuteCtx
impl !RefUnwindSafe for ExecuteCtx
impl Send for ExecuteCtx
impl Sync for ExecuteCtx
impl Unpin for ExecuteCtx
impl !UnwindSafe for ExecuteCtx
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more