Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

wasmtime-wasi-http: Replace new_incoming_request's hyper::Error to Into<ErrorCode> (#12227)

Nam Se Hyund175767146e6
diff --git a/crates/wasi-http/src/error.rs b/crates/wasi-http/src/error.rs
index 8a2c2cf0fc..9c0a562b41 100644
--- a/crates/wasi-http/src/error.rs
+++ b/crates/wasi-http/src/error.rs
@@ -112,3 +112,9 @@ pub fn hyper_response_error(err: hyper::Error) -> ErrorCode {
ErrorCode::HttpProtocolError
}
+
+impl From<hyper::Error> for ErrorCode {
+ fn from(err: hyper::Error) -> Self {
+ hyper_response_error(err)
+ }
+}
diff --git a/crates/wasi-http/src/types.rs b/crates/wasi-http/src/types.rs
index 0eb1d31a93..61f4d0a9d1 100644
--- a/crates/wasi-http/src/types.rs
+++ b/crates/wasi-http/src/types.rs
@@ -2,7 +2,7 @@
//! implementation of the wasi-http API.
use crate::{
- bindings::http::types::{self, Method, Scheme},
+ bindings::http::types::{self, ErrorCode, Method, Scheme},
body::{HostIncomingBody, HyperIncomingBody, HyperOutgoingBody},
};
use anyhow::bail;
@@ -92,11 +92,12 @@ pub trait WasiHttpView {
req: hyper::Request<B>,
) -> wasmtime::Result<Resource<HostIncomingRequest>>
where
- B: Body<Data = Bytes, Error = hyper::Error> + Send + 'static,
+ B: Body<Data = Bytes> + Send + 'static,
+ B::Error: Into<ErrorCode>,
Self: Sized,
{
let (parts, body) = req.into_parts();
- let body = body.map_err(crate::hyper_response_error).boxed_unsync();
+ let body = body.map_err(Into::into).boxed_unsync();
let body = HostIncomingBody::new(
body,
// TODO: this needs to be plumbed through