Skip to content

Commit

Permalink
Trap when conversion from millis to u32 would fail
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed Oct 30, 2023
1 parent 87a1d58 commit e6e46b9
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions crates/wasi-http/src/types_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,17 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostRequestOptions for T {
&mut self,
opts: Resource<types::RequestOptions>,
) -> wasmtime::Result<Option<u32>> {
Ok(self
let millis = self
.table()
.get(&opts)?
.connect_timeout
.and_then(|d| d.as_millis().try_into().ok()))
.map(|d| d.as_millis());

if let Some(millis) = millis {
Ok(Some(millis.try_into()?))
} else {
Ok(None)
}
}

fn set_connect_timeout_ms(
Expand All @@ -762,11 +768,17 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostRequestOptions for T {
&mut self,
opts: Resource<types::RequestOptions>,
) -> wasmtime::Result<Option<u32>> {
Ok(self
let millis = self
.table()
.get(&opts)?
.first_byte_timeout
.and_then(|d| d.as_millis().try_into().ok()))
.map(|d| d.as_millis());

if let Some(millis) = millis {
Ok(Some(millis.try_into()?))
} else {
Ok(None)
}
}

fn set_first_byte_timeout_ms(
Expand All @@ -783,11 +795,17 @@ impl<T: WasiHttpView> crate::bindings::http::types::HostRequestOptions for T {
&mut self,
opts: Resource<types::RequestOptions>,
) -> wasmtime::Result<Option<u32>> {
Ok(self
let millis = self
.table()
.get(&opts)?
.between_bytes_timeout
.and_then(|d| d.as_millis().try_into().ok()))
.map(|d| d.as_millis());

if let Some(millis) = millis {
Ok(Some(millis.try_into()?))
} else {
Ok(None)
}
}

fn set_between_bytes_timeout_ms(
Expand Down

0 comments on commit e6e46b9

Please sign in to comment.