pub async fn inspect_generic_request_map_async<GH: Grasshopper>(
    configpath: &str,
    mgh: Option<GH>,
    raw: RawRequest<'_>,
    logs: &mut Logs,
) -> (Decision, Tags, RequestInfo) {
    let mut tags = Tags::default();

    // insert the all tag here, to make sure it is always present, even in the presence of early errors
    tags.insert("all");

    logs.debug(|| format!("Inspection starts (grasshopper active: {})", mgh.is_some()));

    #[allow(clippy::large_enum_variant)]
    enum RequestMappingResult<A> {
        NoSecurityPolicy,
        BodyTooLarge(Action, RequestInfo),
        Res(A),
    }

    // do all config queries in the lambda once
    // there is a lot of copying taking place, to minimize the lock time
    // this decision should be backed with benchmarks

    let ((nm, securitypolicy), (ntags, globalfilter_dec), flows, reqinfo, is_human) =
        match with_config(configpath, logs, |slogs, cfg| {
            let mmapinfo =
                match_securitypolicy(&raw.get_host(), &raw.meta.path, cfg, slogs).map(|(nm, um)| (nm, um.clone()));
            match mmapinfo {
                Some((nm, secpolicy)) => {
                    // this part is where we use the configuration as much as possible, while we have a lock on it
                    let pmax_depth = secpolicy.content_filter_profile.max_body_depth;

                    // check if the body is too large
                    // if the body is too large, we store the "too large" action for later use, and set the max depth to 0
                    let (body_too_large, max_depth) = if let Some(body) = raw.mbody {
                        if body.len() > secpolicy.content_filter_profile.max_body_size {
                            (
                                Some(body_too_large(
                                    secpolicy.content_filter_profile.max_body_size,
                                    body.len(),
                                )),
                                0,
                            )
                        } else {
                            (None, pmax_depth)
                        }
                    } else {
                        (None, pmax_depth)
                    };

                    // if the max depth is equal to 0, the body will not be parsed
                    let reqinfo = map_request(
                        slogs,
                        &secpolicy.content_filter_profile.decoding,
                        &secpolicy.content_filter_profile.content_type,
                        max_depth,
                        &raw,
                    );

                    if let Some(action) = body_too_large {
                        return RequestMappingResult::BodyTooLarge(action, reqinfo);
                    }

                    let nflows = cfg.flows.clone();

                    // without grasshopper, default to being human
                    let is_human = if let Some(gh) = &mgh {
                        challenge_verified(gh, &reqinfo, slogs)
                    } else {
                        false
                    };

                    let ntags = tag_request(is_human, &cfg.globalfilters, &reqinfo);
                    RequestMappingResult::Res(((nm, secpolicy), ntags, nflows, reqinfo, is_human))
                }
                None => RequestMappingResult::NoSecurityPolicy,
            }
        }) {
            Some(RequestMappingResult::Res(x)) => x,
            Some(RequestMappingResult::BodyTooLarge(action, rinfo)) => {
                return (Decision::Action(action), tags, rinfo);
            }
            Some(RequestMappingResult::NoSecurityPolicy) => {
                logs.debug("No security policy found");
                return (Decision::Pass, tags, map_request(logs, &[], &[], 0, &raw));
            }
            None => {
                logs.debug("Something went wrong during security policy searching");
                return (Decision::Pass, tags, map_request(logs, &[], &[], 0, &raw));
            }
        };

    tags.extend(ntags);
    analyze::analyze(
        logs,
        mgh,
        tags,
        &nm,
        &securitypolicy,
        reqinfo,
        is_human,
        globalfilter_dec,
        &flows,
    )
    .await
}
// generic entry point when the request map has already been parsed
generic entry point when the request map has already been parsed
generic entry point when the request map has already been parsed
pub async fn inspect_generic_request_map_async<GH: Grasshopper>(
    configpath: &str,
    mgh: Option<GH>,
    raw: RawRequest<'_>,
    logs: &mut Logs,
) -> (Decision, Tags, RequestInfo) {
    let mut tags = Tags::default();
    // insert the all tag here, to make sure it is always present, even in the presence of early errors
    tags.insert("all");
    logs.debug(|| format!("Inspection starts (grasshopper active: {})", mgh.is_some()));
    #[allow(clippy::large_enum_variant)]
    enum RequestMappingResult<A> {
        NoSecurityPolicy,
        BodyTooLarge(Action, RequestInfo),
        Res(A),
    }
    // do all config queries in the lambda once
    // there is a lot of copying taking place, to minimize the lock time
    // this decision should be backed with benchmarks
    let ((nm, securitypolicy), (ntags, globalfilter_dec), flows, reqinfo, is_human) =
        match with_config(configpath, logs, |slogs, cfg| {
            let mmapinfo =
                match_securitypolicy(&raw.get_host(), &raw.meta.path, cfg, slogs).map(|(nm, um)| (nm, um.clone()));
            match mmapinfo {
                Some((nm, secpolicy)) => {
                    // this part is where we use the configuration as much as possible, while we have a lock on it
                    let pmax_depth = secpolicy.content_filter_profile.max_body_depth;
                    // check if the body is too large
                    // if the body is too large, we store the "too large" action for later use, and set the max depth to 0
                    let (body_too_large, max_depth) = if let Some(body) = raw.mbody {
                        if body.len() > secpolicy.content_filter_profile.max_body_size {
                            (
                                Some(body_too_large(
                                    secpolicy.content_filter_profile.max_body_size,
                                    body.len(),
                                )),
                                0,
                            )
                        } else {
                            (None, pmax_depth)
                        }
                    } else {
                        (None, pmax_depth)
                    };
                    // if the max depth is equal to 0, the body will not be parsed
                    let reqinfo = map_request(
                        slogs,
                        &secpolicy.content_filter_profile.decoding,
                        &secpolicy.content_filter_profile.content_type,
                        max_depth,
                        &raw,
                    );
                    if let Some(action) = body_too_large {
                        return RequestMappingResult::BodyTooLarge(action, reqinfo);
                    }
                    let nflows = cfg.flows.clone();
                    // without grasshopper, default to being human
                    let is_human = if let Some(gh) = &mgh {
                        challenge_verified(gh, &reqinfo, slogs)
                    } else {
                        false
                    };
                    let ntags = tag_request(is_human, &cfg.globalfilters, &reqinfo);
                    RequestMappingResult::Res(((nm, secpolicy), ntags, nflows, reqinfo, is_human))
                }
                None => RequestMappingResult::NoSecurityPolicy,
            }
        }) {
            Some(RequestMappingResult::Res(x)) => x,
            Some(RequestMappingResult::BodyTooLarge(action, rinfo)) => {
                return (Decision::Action(action), tags, rinfo);
            }
            Some(RequestMappingResult::NoSecurityPolicy) => {
                logs.debug("No security policy found");
                return (Decision::Pass, tags, map_request(logs, &[], &[], 0, &raw));
            }
            None => {
                logs.debug("Something went wrong during security policy searching");
                return (Decision::Pass, tags, map_request(logs, &[], &[], 0, &raw));
            }
        };
    tags.extend(ntags);
    analyze::analyze(
        logs,
        mgh,
        tags,
        &nm,
        &securitypolicy,
        reqinfo,
        is_human,
        globalfilter_dec,
        &flows,
    )
    .await
}
pub async fn inspect_generic_request_map_async < GH : Grasshopper > ( configpath : & str , mgh : Option < GH > , raw : RawRequest < ' _ > , logs : & mut Logs , ) -> ( Decision , Tags , RequestInfo ) { let mut tags = Tags :: default ( ) ; // insert the all tag here, to make sure it is always present, even in the presence of early errors tags . insert ( " " ) ; logs . debug ( | | format ! ( " " mgh is_some ( ) ) ) ; # [ allow ( clippy large_enum_variant ) ] enum RequestMappingResult < A > { NoSecurityPolicy , BodyTooLarge ( Action , RequestInfo ) , Res ( A ) , } // do all config queries in the lambda once // there is a lot of copying taking place, to minimize the lock time // this decision should be backed with benchmarks let ( ( nm , securitypolicy ) , ( ntags , globalfilter_dec ) , flows , reqinfo , is_human ) = match with_config ( configpath , logs , | slogs , cfg | { let mmapinfo = match_securitypolicy ( & raw . get_host ( ) , & raw . meta . path , cfg , slogs ) . map ( | ( nm , um ) | ( nm , um . clone ( ) ) ) ; match mmapinfo { Some ( ( nm , secpolicy ) ) => { // this part is where we use the configuration as much as possible, while we have a lock on it let pmax_depth = secpolicy . content_filter_profile . max_body_depth ; // check if the body is too large // if the body is too large, we store the "too large" action for later use, and set the max depth to 0 let ( body_too_large , max_depth ) = if let Some ( body ) = raw . mbody { if body . len ( ) > secpolicy . content_filter_profile . max_body_size { ( Some ( body_too_large ( secpolicy . content_filter_profile . max_body_size , body . len ( ) , ) ) , 0 , ) } else { ( None , pmax_depth ) } } else { ( None , pmax_depth ) } ; // if the max depth is equal to 0, the body will not be parsed let reqinfo = map_request ( slogs , & secpolicy . content_filter_profile . decoding , & secpolicy . content_filter_profile . content_type , max_depth , & raw , ) ; if let Some ( action ) = body_too_large { return RequestMappingResult :: BodyTooLarge ( action , reqinfo ) ; } let nflows = cfg . flows . clone ( ) ; // without grasshopper, default to being human let is_human = if let Some ( gh ) = & mgh { challenge_verified ( gh , & reqinfo , slogs ) } else { false } ; let ntags = tag_request ( is_human , & cfg . globalfilters , & reqinfo ) ; RequestMappingResult :: Res ( ( ( nm , secpolicy ) , ntags , nflows , reqinfo , is_human ) ) } None => RequestMappingResult :: NoSecurityPolicy , } } ) { Some ( RequestMappingResult :: Res ( x ) ) => x , Some ( RequestMappingResult :: BodyTooLarge ( action , rinfo ) ) => { return ( Decision :: Action ( action ) , tags , rinfo ) ; } Some ( RequestMappingResult :: NoSecurityPolicy ) => { logs . debug ( " " ) ; return ( Decision :: Pass , tags , map_request ( logs , & [ ] , & [ ] , 0 , & raw ) ) ; } None => { logs . debug ( " " ) ; return ( Decision :: Pass , tags , map_request ( logs , & [ ] , & [ ] , 0 , & raw ) ) ; } } ; tags . extend ( ntags ) ; analyze :: analyze ( logs , mgh , tags , & nm , & securitypolicy , reqinfo , is_human , globalfilter_dec , & flows , ) . await }
generic entry point when the request map has already been parsed
generic entry point when the request map has already been parsed
configpath
&str
mgh
Option<GH>
raw
RawRequest<'_>
logs
&mut Logs