Skip to content

Commit d175767

Browse files
authored
wasmtime-wasi-http: Replace new_incoming_request's hyper::Error to Into<ErrorCode> (#12227)
1 parent 4563107 commit d175767

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

crates/wasi-http/src/error.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,9 @@ pub fn hyper_response_error(err: hyper::Error) -> ErrorCode {
112112

113113
ErrorCode::HttpProtocolError
114114
}
115+
116+
impl From<hyper::Error> for ErrorCode {
117+
fn from(err: hyper::Error) -> Self {
118+
hyper_response_error(err)
119+
}
120+
}

crates/wasi-http/src/types.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! implementation of the wasi-http API.
33
44
use crate::{
5-
bindings::http::types::{self, Method, Scheme},
5+
bindings::http::types::{self, ErrorCode, Method, Scheme},
66
body::{HostIncomingBody, HyperIncomingBody, HyperOutgoingBody},
77
};
88
use anyhow::bail;
@@ -92,11 +92,12 @@ pub trait WasiHttpView {
9292
req: hyper::Request<B>,
9393
) -> wasmtime::Result<Resource<HostIncomingRequest>>
9494
where
95-
B: Body<Data = Bytes, Error = hyper::Error> + Send + 'static,
95+
B: Body<Data = Bytes> + Send + 'static,
96+
B::Error: Into<ErrorCode>,
9697
Self: Sized,
9798
{
9899
let (parts, body) = req.into_parts();
99-
let body = body.map_err(crate::hyper_response_error).boxed_unsync();
100+
let body = body.map_err(Into::into).boxed_unsync();
100101
let body = HostIncomingBody::new(
101102
body,
102103
// TODO: this needs to be plumbed through

0 commit comments

Comments
 (0)