Skip to content

Commit 9ef5874

Browse files
committed
feat(http): ensure WasiHttp is Clone + Sync + Send
This should be redundant, but is required by the existing Wasmtime design Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
1 parent 0eea430 commit 9ef5874

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

crates/wasi-http/src/http_impl.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ impl WasiHttp {
137137
// TODO: Configurable default
138138
Duration::from_millis(600)
139139
};
140-
let mut body = res.into_body();
140+
let body = res.into_body();
141+
let mut body = body.lock().await;
141142
let mut buf = BytesMut::new();
142143
while let Some(next) = timeout(between_bytes_timeout, body.frame()).await? {
143144
let frame = next?;

crates/wasi-http/src/struct.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use async_trait::async_trait;
99
use bytes::{BufMut, Bytes, BytesMut};
1010
use http_body_util::Full;
1111
use tokio::net::TcpStream;
12+
use tokio::sync::Mutex;
1213
use tokio::time;
1314

1415
#[derive(Clone, Default)]
@@ -24,7 +25,7 @@ impl From<Stream> for Bytes {
2425
}
2526

2627
#[derive(Clone)]
27-
pub struct WasiHttp<Response = hyper::body::Incoming> {
28+
pub struct WasiHttp<Response = Arc<Mutex<hyper::body::Incoming>>> {
2829
pub outgoing_handler: Arc<Box<dyn OutgoingHandler<Body = Response>>>,
2930
pub request_id_base: u32,
3031
pub response_id_base: u32,
@@ -106,7 +107,7 @@ impl From<Bytes> for Stream {
106107
}
107108

108109
#[async_trait]
109-
pub trait OutgoingHandler {
110+
pub trait OutgoingHandler: Sync + Send {
110111
type Body;
111112

112113
async fn handle(
@@ -123,7 +124,7 @@ pub struct DefaultOutgoingHandler;
123124

124125
#[async_trait]
125126
impl OutgoingHandler for DefaultOutgoingHandler {
126-
type Body = hyper::body::Incoming;
127+
type Body = Arc<Mutex<hyper::body::Incoming>>;
127128

128129
async fn handle(
129130
&self,
@@ -202,6 +203,7 @@ impl OutgoingHandler for DefaultOutgoingHandler {
202203
time::timeout(first_byte_timeout, sender.send_request(request))
203204
.await
204205
.context("request timed out")?
206+
.map(|res| res.map(|b| Arc::new(Mutex::new(b))))
205207
.context("failed to send request")
206208
}
207209
}

0 commit comments

Comments
 (0)