Skip to main content

wasi_hyperium/
lib.rs

1mod incoming;
2pub mod outgoing;
3pub mod poll;
4pub mod wasi;
5
6use ::wasi::{http::types::ErrorCode, io::streams::StreamError};
7pub use incoming::IncomingHttpBody;
8
9#[cfg(feature = "hyperium0")]
10pub mod hyperium0;
11#[cfg(feature = "hyperium1")]
12pub mod hyperium1;
13
14#[derive(Debug, thiserror::Error)]
15pub enum Error {
16    #[error(transparent)]
17    BodyError(anyhow::Error),
18
19    #[error("{0}")]
20    WasiError(String),
21    #[error("{0}")]
22    WasiErrorCode(String),
23    #[error("{0}")]
24    WasiFieldsError(String),
25    #[error("{0}")]
26    WasiInvalidState(&'static str),
27    #[error("{0}")]
28    WasiInvalidValue(&'static str),
29    #[error("stream error: {0}")]
30    WasiStreamOperationFailed(String),
31    #[error("stream closed")]
32    WasiStreamClosed,
33
34    #[cfg(feature = "hyperium0")]
35    #[error(transparent)]
36    Hyperium0Error(#[from] http0::Error),
37    #[cfg(feature = "hyperium1")]
38    #[error(transparent)]
39    Hyperium1Error(#[from] http1::Error),
40}
41
42impl Error {
43    fn wasi_error_code(err: ErrorCode) -> Self {
44        Self::WasiErrorCode(err.to_string())
45    }
46
47    fn wasi_stream_error(err: StreamError) -> Self {
48        match err {
49            StreamError::LastOperationFailed(err) => {
50                Self::WasiStreamOperationFailed(err.to_debug_string())
51            }
52            StreamError::Closed => Self::WasiStreamClosed,
53        }
54    }
55}