wstd 0.5.0-draft2

An async standard library for Wasm Components and WASI 0.2
Documentation
use wasi::http::types::Method as WasiMethod;

use super::Result;
pub use http::Method;

pub(crate) fn to_wasi_method(value: Method) -> WasiMethod {
    match value {
        Method::GET => WasiMethod::Get,
        Method::HEAD => WasiMethod::Head,
        Method::POST => WasiMethod::Post,
        Method::PUT => WasiMethod::Put,
        Method::DELETE => WasiMethod::Delete,
        Method::CONNECT => WasiMethod::Connect,
        Method::OPTIONS => WasiMethod::Options,
        Method::TRACE => WasiMethod::Trace,
        Method::PATCH => WasiMethod::Patch,
        other => WasiMethod::Other(other.as_str().to_owned()),
    }
}

// This will become useful once we support IncomingRequest
#[allow(dead_code)]
pub(crate) fn from_wasi_method(value: WasiMethod) -> Result<Method> {
    Ok(match value {
        WasiMethod::Get => Method::GET,
        WasiMethod::Head => Method::HEAD,
        WasiMethod::Post => Method::POST,
        WasiMethod::Put => Method::PUT,
        WasiMethod::Delete => Method::DELETE,
        WasiMethod::Connect => Method::CONNECT,
        WasiMethod::Options => Method::OPTIONS,
        WasiMethod::Trace => Method::TRACE,
        WasiMethod::Patch => Method::PATCH,
        WasiMethod::Other(s) => Method::from_bytes(s.as_bytes())?,
    })
}