wasmtime-wasi-http-plus 0.0.2

An enhanced implementation of wasmtime-wasi-http
Documentation
use super::request::*;

use {
    hyper::*,
    read_url::*,
    wasmtime_wasi::runtime::*,
    wasmtime_wasi_http::p2::{body::*, types::*, *},
};

//
// WasiHttpPlusHooks
//

/// HTTP hooks for WASI HTTP+.
///
/// We are overriding `send_request` in order to support TLS configuration.
///
/// Uses (and removes) the following custom headers, which are all URLs to X.509 certificates
/// encoded as PEM (Privacy-Enhanced Mail):
///
/// * `XX-Root-Certificates`
/// * `XX-Certificates`
/// * `XX-Private-Key`
pub struct WasiHttpPlusHooks {
    url_context: UrlContextRef,
}

impl WasiHttpPlusHooks {
    /// Constructor.
    pub fn new(url_context: UrlContextRef) -> Self {
        Self { url_context }
    }
}

impl WasiHttpHooks for WasiHttpPlusHooks {
    fn send_request(
        &mut self,
        request: Request<HyperOutgoingBody>,
        config: OutgoingRequestConfig,
    ) -> HttpResult<HostFutureIncomingResponse> {
        let url_context = self.url_context.clone();
        let handle = spawn(async move { Ok(send_request_plus(request, config, url_context).await) });
        Ok(HostFutureIncomingResponse::pending(handle))
    }
}