/// Routes an `XNetEndpoint` request to the appropriate handler; or produces an
/// HTTP 404 Not Found response if the URL doesn't match any handler.
Routes an `XNetEndpoint` request to the appropriate handler; or produces an
HTTP 404 Not Found response if the URL doesn't match any handler.
Routes an ` XNetEndpoint ` request to the appropriate handler ; or produces an HTTP 404 Not Found response if the URL doesn ' t match any handler .
fn route_request(
    url: Url,
    certified_stream_store: &dyn CertifiedStreamStore,
    metrics: &XNetEndpointMetrics,
) -> Response<Body> {
    let timer = Timer::start();
    let mut resource = RESOURCE_ERROR;
    let response = match url.path() {
        API_URL_STREAMS => {
            resource = RESOURCE_STREAMS;
            handle_streams(certified_stream_store, metrics)
        }
        stream_url if stream_url.starts_with(API_URL_STREAM_PREFIX) => {
            resource = RESOURCE_STREAM;
            let subnet_id_str = &stream_url[API_URL_STREAM_PREFIX.len()..];
            let subnet_id = match PrincipalId::from_str(subnet_id_str) {
                Ok(subnet_id) => SubnetId::from(subnet_id),
                Err(_) => {
                    return bad_request(format!(
                        "Invalid subnet ID: {} in {}",
                        subnet_id_str, stream_url
                    ))
                }
            };
            let mut witness_begin = None;
            let mut msg_begin = None;
            let mut msg_limit = None;
            let mut byte_limit = None;
            for (param, value) in url.query_pairs() {
                let value = match value.parse::<u64>() {
                    Ok(v) => v,
                    Err(_) => {
                        return bad_request(format!("Invalid query param: {}", param));
                    }
                };
                match param.as_ref() {
                    "witness_begin" => witness_begin = Some(StreamIndex::new(value)),
                    "index" => msg_begin = Some(StreamIndex::new(value)),
                    "msg_begin" => msg_begin = Some(StreamIndex::new(value)),
                    "msg_limit" => msg_limit = Some(value as usize),
                    "byte_limit" => byte_limit = Some(value as usize),
                    _ => {
                        return bad_request(format!("Unexpected query param: {}", param));
                    }
                }
            }
            handle_stream(
                subnet_id,
                witness_begin,
                msg_begin,
                msg_limit,
                byte_limit,
                certified_stream_store,
                metrics,
            )
        }
        _ => not_found("Not Found"),
    };
    metrics
        .request_duration
        .with_label_values(&[resource, response.status().as_str()])
        .observe(timer.elapsed());
    response
}
fn route_request ( url : Url , certified_stream_store : & dyn CertifiedStreamStore , metrics : & XNetEndpointMetrics , ) -> Response < Body > { let timer = Timer :: start ( ) ; let mut resource = RESOURCE_ERROR ; let response = match url . path ( ) { API_URL_STREAMS => { resource = RESOURCE_STREAMS ; handle_streams ( certified_stream_store , metrics ) } stream_url if stream_url . starts_with ( API_URL_STREAM_PREFIX ) => { resource = RESOURCE_STREAM ; let subnet_id_str = & stream_url [ API_URL_STREAM_PREFIX . len ( ) .. ] ; let subnet_id = match PrincipalId :: from_str ( subnet_id_str ) { Ok ( subnet_id ) => SubnetId :: from ( subnet_id ) , Err ( _ ) => { return bad_request ( format ! ( " " subnet_id_str stream_url ) ) } } ; let mut witness_begin = None ; let mut msg_begin = None ; let mut msg_limit = None ; let mut byte_limit = None ; for ( param , value ) in url . query_pairs ( ) { let value = match value . parse :: < u64 > ( ) { Ok ( v ) => v , Err ( _ ) => { return bad_request ( format ! ( " " param ) ) ; } } ; match param . as_ref ( ) { " " => witness_begin = Some ( StreamIndex :: new ( value ) ) , " " => msg_begin = Some ( StreamIndex :: new ( value ) ) , " " => msg_begin = Some ( StreamIndex :: new ( value ) ) , " " => msg_limit = Some ( value as usize ) , " " => byte_limit = Some ( value as usize ) , _ => { return bad_request ( format ! ( " " param ) ) ; } } } handle_stream ( subnet_id , witness_begin , msg_begin , msg_limit , byte_limit , certified_stream_store , metrics , ) } _ => not_found ( " " ) , } ; metrics . request_duration . with_label_values ( & [ resource , response . status ( ) . as_str ( ) ] ) . observe ( timer . elapsed ( ) ) ; response }
Routes an `XNetEndpoint` request to the appropriate handler; or produces an
HTTP 404 Not Found response if the URL doesn't match any handler.
Routes an ` XNetEndpoint ` request to the appropriate handler ; or produces an HTTP 404 Not Found response if the URL doesn ' t match any handler .
url
Url
certified_stream_store
&dyn CertifiedStreamStore
metrics
&XNetEndpointMetrics