wasi_hyperium/
hyperium0.rs1mod incoming;
2mod outgoing;
3mod service;
4
5pub use incoming::incoming_request;
6pub use outgoing::{outgoing_response, Hyperium0OutgoingBodyCopier};
7pub use service::handle_service_call;
8
9use crate::wasi::{FieldEntries, Method, Scheme};
10
11impl TryFrom<Method> for http0::Method {
12 type Error = http0::Error;
13
14 fn try_from(method: Method) -> Result<Self, Self::Error> {
15 Ok(match method {
16 Method::Get => Self::GET,
17 Method::Head => Self::HEAD,
18 Method::Post => Self::POST,
19 Method::Put => Self::PUT,
20 Method::Delete => Self::DELETE,
21 Method::Connect => Self::CONNECT,
22 Method::Options => Self::OPTIONS,
23 Method::Trace => Self::TRACE,
24 Method::Patch => Self::PATCH,
25 Method::Other(other) => other.parse()?,
26 })
27 }
28}
29
30impl TryFrom<Scheme> for http0::uri::Scheme {
31 type Error = http0::Error;
32 fn try_from(scheme: Scheme) -> Result<Self, Self::Error> {
33 Ok(match scheme {
34 Scheme::Http => Self::HTTP,
35 Scheme::Https => Self::HTTPS,
36 Scheme::Other(other) => other.parse()?,
37 })
38 }
39}
40
41impl TryFrom<FieldEntries> for http0::HeaderMap {
42 type Error = http0::Error;
43
44 fn try_from(entries: FieldEntries) -> Result<Self, Self::Error> {
45 entries
46 .into_iter()
47 .map(|(name, val)| Ok((name.try_into()?, val.try_into()?)))
48 .collect()
49 }
50}
51
52impl From<http0::HeaderMap> for FieldEntries {
53 fn from(map: http0::HeaderMap) -> Self {
54 (&map).into()
55 }
56}
57
58impl From<&http0::HeaderMap> for FieldEntries {
59 fn from(map: &http0::HeaderMap) -> Self {
60 map.iter()
61 .map(|(name, val)| (name.to_string(), val.as_bytes().to_vec()))
62 .collect::<Vec<_>>()
63 .into()
64 }
65}