-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cargo.toml: remove unused dependnecies
Signed-off-by: jiaxiao zhou <[email protected]>
- Loading branch information
Showing
8 changed files
with
466 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use containerd_shim_wasm::container::WasmBinaryType; | ||
use wasmtime::component::Component; | ||
|
||
use crate::instance::{WasiConfig, WasmtimeEngine}; | ||
|
||
pub(crate) enum Worlds { | ||
WasiHTTPProxy, | ||
WasiCLICommand, | ||
} | ||
|
||
impl<T> WasmtimeEngine<T> | ||
where | ||
T: std::clone::Clone + Sync + WasiConfig + Send + 'static, | ||
{ | ||
pub(crate) fn detect_world(&self, component: Component) -> Worlds { | ||
let ty = component.component_type(); | ||
for (name, _) in ty.exports(&self.engine) { | ||
match name { | ||
"wasi:http/[email protected]" | "wasi:http/[email protected]" => { | ||
return Worlds::WasiHTTPProxy | ||
} | ||
_ => {} | ||
} | ||
} | ||
Worlds::WasiCLICommand | ||
} | ||
|
||
// best effort to detect if the wasm component is targeting a wasi-http proxy | ||
pub fn is_wasi_http(&self, wasm_bytes: &std::borrow::Cow<'_, [u8]>) -> anyhow::Result<bool> { | ||
let res = match WasmBinaryType::from_bytes(wasm_bytes) { | ||
Some(WasmBinaryType::Component) => { | ||
let component = Component::from_binary(&self.engine, wasm_bytes)?; | ||
match self.detect_world(component) { | ||
Worlds::WasiHTTPProxy => true, | ||
_ => false, | ||
} | ||
} | ||
Some(_) => false, | ||
None => false, | ||
}; | ||
Ok(res) | ||
} | ||
} |
Oops, something went wrong.