pub async fn request_router<P: Provider + Sync>(
        tail: warp::path::Tail,
        query: InvoiceQuery,
        store: P,
        method: Method,
    ) -> Result<Box<dyn warp::Reply>, Infallible> {
        let split: Vec<&str> = tail.as_str().split(PARCEL_ID_SEPARATOR).collect();

        match split.len() {
            1 => {
                trace!(
                    "Matched only bindle ID {}, routing to get/head invoice handler",
                    split[0]
                );
                match method {
                    Method::HEAD => head_invoice(tail, query, store).await,
                    Method::GET => get_invoice(tail, query, store).await,
                    _ => Ok(Box::new(reply::reply_from_error(
                        "Got invalid method",
                        warp::http::StatusCode::METHOD_NOT_ALLOWED,
                    ))),
                }
            }
            2 => {
                trace!(
                    "Matched bindle ID {} and sha {}, routing to get parcel handler",
                    split[0],
                    split[1]
                );
                match method {
                    Method::HEAD => head_parcel(split[0], split[1], store).await,
                    Method::GET => get_parcel(split[0], split[1], store).await,
                    _ => Ok(Box::new(reply::reply_from_error(
                        "Got invalid method",
                        warp::http::StatusCode::METHOD_NOT_ALLOWED,
                    ))),
                }
            }
            _ => Ok(Box::new(reply::reply_from_error(
                "Invalid URL. Missing bindle ID and/or parcel SHA",
                warp::http::StatusCode::BAD_REQUEST,
            ))),
        }
    }
/// Due to subpathed parcel support, we need to check what is in the tail of a GET request in order to route the request to the appropriate handler
Due to subpathed parcel support, we need to check what is in the tail of a GET request in order to route the request to the appropriate handler
Due to subpathed parcel support we need to check what is in the tail of a GET request in order to route the request to the appropriate handler
pub async fn request_router<P: Provider + Sync>(
        tail: warp::path::Tail,
        query: InvoiceQuery,
        store: P,
        method: Method,
    ) -> Result<Box<dyn warp::Reply>, Infallible> {
        let split: Vec<&str> = tail.as_str().split(PARCEL_ID_SEPARATOR).collect();
        match split.len() {
            1 => {
                trace!(
                    "Matched only bindle ID {}, routing to get/head invoice handler",
                    split[0]
                );
                match method {
                    Method::HEAD => head_invoice(tail, query, store).await,
                    Method::GET => get_invoice(tail, query, store).await,
                    _ => Ok(Box::new(reply::reply_from_error(
                        "Got invalid method",
                        warp::http::StatusCode::METHOD_NOT_ALLOWED,
                    ))),
                }
            }
            2 => {
                trace!(
                    "Matched bindle ID {} and sha {}, routing to get parcel handler",
                    split[0],
                    split[1]
                );
                match method {
                    Method::HEAD => head_parcel(split[0], split[1], store).await,
                    Method::GET => get_parcel(split[0], split[1], store).await,
                    _ => Ok(Box::new(reply::reply_from_error(
                        "Got invalid method",
                        warp::http::StatusCode::METHOD_NOT_ALLOWED,
                    ))),
                }
            }
            _ => Ok(Box::new(reply::reply_from_error(
                "Invalid URL. Missing bindle ID and/or parcel SHA",
                warp::http::StatusCode::BAD_REQUEST,
            ))),
        }
    }
pub async fn request_router < P : Provider + Sync > ( tail : warp :: path :: Tail , query : InvoiceQuery , store : P , method : Method , ) -> Result < Box < dyn warp :: Reply > , Infallible > { let split : Vec < & str > = tail . as_str ( ) . split ( PARCEL_ID_SEPARATOR ) . collect ( ) ; match split . len ( ) { 1 => { trace ! ( " " split [ 0 ] ) ; match method { Method :: HEAD => head_invoice ( tail , query , store ) . await , Method :: GET => get_invoice ( tail , query , store ) . await , _ => Ok ( Box :: new ( reply :: reply_from_error ( " " , warp :: http :: StatusCode :: METHOD_NOT_ALLOWED , ) ) ) , } } 2 => { trace ! ( " " split [ 0 ] split [ 1 ] ) ; match method { Method :: HEAD => head_parcel ( split [ 0 ] , split [ 1 ] , store ) . await , Method :: GET => get_parcel ( split [ 0 ] , split [ 1 ] , store ) . await , _ => Ok ( Box :: new ( reply :: reply_from_error ( " " , warp :: http :: StatusCode :: METHOD_NOT_ALLOWED , ) ) ) , } } _ => Ok ( Box :: new ( reply :: reply_from_error ( " " , warp :: http :: StatusCode :: BAD_REQUEST , ) ) ) , } }
Due to subpathed parcel support, we need to check what is in the tail of a GET request in order to route the request to the appropriate handler
Due to subpathed parcel support we need to check what is in the tail of a GET request in order to route the request to the appropriate handler
tail
warp::path::Tail
query
InvoiceQuery
store
P
method
Method
tail
warp::path::Tail
query
InvoiceQuery
store
P
method
Method