pub async fn route(
        &self,
        req: Request<Body>,
        client_addr: SocketAddr,
    ) -> Result<Response<Body>, hyper::Error> {
        // TODO: Improve the loading. See issue #3
        //
        // Additionally, we could implement an LRU to cache WASM modules. This would
        // greatly reduce the amount of load time per request. But this would come with two
        // drawbacks: (a) it would be different than CGI, and (b) it would involve a cache
        // clear during debugging, which could be a bit annoying.

        log::trace!("Processing request to {}", req.uri());

        let uri_path = req.uri().path();
        let host = req
            .headers()
            .get(HOST)
            .map(|val| val.to_str().unwrap_or(""))
            .unwrap_or("");
        match uri_path {
            "/healthz" => Ok(Response::new(Body::from("OK"))),
            _ => match self
                .module_store
                .handler_for_host_path(host.to_lowercase().as_str(), uri_path)
                .await
            {
                Ok(h) => {
                    let cache_config_path = self.module_store.cache_config_path.clone();
                    let module_cache_dir = self.module_store.module_cache.clone();
                    let res = h
                        .module
                        .execute(
                            h.entrypoint.as_str(),
                            req,
                            client_addr,
                            cache_config_path,
                            module_cache_dir,
                        )
                        .await;
                    Ok(res)
                }
                Err(e) => {
                    log::error!("error: {}", e);
                    Ok(not_found())
                }
            },
        }
    }
/// Route the request to the correct handler
///
/// Some routes are built in (like healthz), while others are dynamically
/// dispatched.
Route the request to the correct handler
Some routes are built in (like healthz), while others are dynamically
dispatched.
Route the request to the correct handler Some routes are built in ( like healthz ) while others are dynamically dispatched .
pub async fn route(
        &self,
        req: Request<Body>,
        client_addr: SocketAddr,
    ) -> Result<Response<Body>, hyper::Error> {
        // TODO: Improve the loading. See issue #3
        //
        // Additionally, we could implement an LRU to cache WASM modules. This would
        // greatly reduce the amount of load time per request. But this would come with two
        // drawbacks: (a) it would be different than CGI, and (b) it would involve a cache
        // clear during debugging, which could be a bit annoying.
        log::trace!("Processing request to {}", req.uri());
        let uri_path = req.uri().path();
        let host = req
            .headers()
            .get(HOST)
            .map(|val| val.to_str().unwrap_or(""))
            .unwrap_or("");
        match uri_path {
            "/healthz" => Ok(Response::new(Body::from("OK"))),
            _ => match self
                .module_store
                .handler_for_host_path(host.to_lowercase().as_str(), uri_path)
                .await
            {
                Ok(h) => {
                    let cache_config_path = self.module_store.cache_config_path.clone();
                    let module_cache_dir = self.module_store.module_cache.clone();
                    let res = h
                        .module
                        .execute(
                            h.entrypoint.as_str(),
                            req,
                            client_addr,
                            cache_config_path,
                            module_cache_dir,
                        )
                        .await;
                    Ok(res)
                }
                Err(e) => {
                    log::error!("error: {}", e);
                    Ok(not_found())
                }
            },
        }
    }
pub async fn route ( & self , req : Request < Body > , client_addr : SocketAddr , ) -> Result < Response < Body > , hyper :: Error > { // TODO: Improve the loading. See issue #3 // // Additionally, we could implement an LRU to cache WASM modules. This would // greatly reduce the amount of load time per request. But this would come with two // drawbacks: (a) it would be different than CGI, and (b) it would involve a cache // clear during debugging, which could be a bit annoying. log :: trace ! ( " " req uri ( ) ) ; let uri_path = req . uri ( ) . path ( ) ; let host = req . headers ( ) . get ( HOST ) . map ( | val | val . to_str ( ) . unwrap_or ( " " ) ) . unwrap_or ( " " ) ; match uri_path { " " => Ok ( Response :: new ( Body :: from ( " " ) ) ) , _ => match self . module_store . handler_for_host_path ( host . to_lowercase ( ) . as_str ( ) , uri_path ) . await { Ok ( h ) => { let cache_config_path = self . module_store . cache_config_path . clone ( ) ; let module_cache_dir = self . module_store . module_cache . clone ( ) ; let res = h . module . execute ( h . entrypoint . as_str ( ) , req , client_addr , cache_config_path , module_cache_dir , ) . await ; Ok ( res ) } Err ( e ) => { log :: error ! ( " " e ) ; Ok ( not_found ( ) ) } } , } }
Route the request to the correct handler
Some routes are built in (like healthz), while others are dynamically
dispatched.
Route the request to the correct handler Some routes are built in ( like healthz ) while others are dynamically dispatched .
&self
req
Request<Body>
client_addr
SocketAddr