fn validate_accept_header(accept: &str, accept_filter: AcceptFilter) -> Result<()> {
    let accept = accept.trim();
    let accept = parse_accept_header(accept)?;
    if accept.is_empty() {
        return Err(anyhow!("Accept header is empty"));
    }
    let q_sxg = accept
        .iter()
        .filter_map(|t| {
            if t.media_range
                .primary_type
                .eq_ignore_ascii_case("application")
                && t.media_range
                    .sub_type
                    .eq_ignore_ascii_case("signed-exchange")
            {
                let mut v = "";
                for param in &t.media_range.parameters {
                    if param.name.eq_ignore_ascii_case("v") {
                        v = &param.value;
                    }
                }
                if v == "b3" {
                    Some(t.q_millis)
                } else {
                    None
                }
            } else {
                None
            }
        })
        .max()
        .unwrap_or(0);
    const SXG: &str = "application/signed-exchange;v=b3";
    if q_sxg == 0 {
        Err(anyhow!(
            "The request accept header does not contain {}.",
            SXG
        ))
    } else {
        match accept_filter {
            AcceptFilter::PrefersSxg => {
                if q_sxg == 1000 {
                    Ok(())
                } else {
                    Err(anyhow!(
                        "The q value of {} is less than 1 in request Accept header.",
                        SXG
                    ))
                }
            }
            AcceptFilter::AcceptsSxg => Ok(()),
        }
    }
}
// Checks whether to serve SXG based on the Accept header of the HTTP request.
// Returns Ok iff the input string has a `application/signed-exchange;v=b3`,
// and either accept_filter != PrefersSxg or its `q` value is 1.
Checks whether to serve SXG based on the Accept header of the HTTP request.
Returns Ok iff the input string has a `application/signed-exchange;v=b3`,
and either accept_filter != PrefersSxg or its `q` value is 1.
Checks whether to serve SXG based on the Accept header of the HTTP request . Returns Ok iff the input string has a ` application / signed - exchange ; v = b3 ` and either accept_filter ! = PrefersSxg or its ` q ` value is 1 .
fn validate_accept_header(accept: &str, accept_filter: AcceptFilter) -> Result<()> {
    let accept = accept.trim();
    let accept = parse_accept_header(accept)?;
    if accept.is_empty() {
        return Err(anyhow!("Accept header is empty"));
    }
    let q_sxg = accept
        .iter()
        .filter_map(|t| {
            if t.media_range
                .primary_type
                .eq_ignore_ascii_case("application")
                && t.media_range
                    .sub_type
                    .eq_ignore_ascii_case("signed-exchange")
            {
                let mut v = "";
                for param in &t.media_range.parameters {
                    if param.name.eq_ignore_ascii_case("v") {
                        v = &param.value;
                    }
                }
                if v == "b3" {
                    Some(t.q_millis)
                } else {
                    None
                }
            } else {
                None
            }
        })
        .max()
        .unwrap_or(0);
    const SXG: &str = "application/signed-exchange;v=b3";
    if q_sxg == 0 {
        Err(anyhow!(
            "The request accept header does not contain {}.",
            SXG
        ))
    } else {
        match accept_filter {
            AcceptFilter::PrefersSxg => {
                if q_sxg == 1000 {
                    Ok(())
                } else {
                    Err(anyhow!(
                        "The q value of {} is less than 1 in request Accept header.",
                        SXG
                    ))
                }
            }
            AcceptFilter::AcceptsSxg => Ok(()),
        }
    }
}
fn validate_accept_header ( accept : & str , accept_filter : AcceptFilter ) -> Result < ( ) > { let accept = accept . trim ( ) ; let accept = parse_accept_header ( accept ) ? ; if accept . is_empty ( ) { return Err ( anyhow ! ( " " ) ) ; } let q_sxg = accept . iter ( ) . filter_map ( | t | { if t . media_range . primary_type . eq_ignore_ascii_case ( " " ) && t . media_range . sub_type . eq_ignore_ascii_case ( " " ) { let mut v = " " ; for param in & t . media_range . parameters { if param . name . eq_ignore_ascii_case ( " " ) { v = & param . value ; } } if v == " " { Some ( t . q_millis ) } else { None } } else { None } } ) . max ( ) . unwrap_or ( 0 ) ; const SXG : & str = " " ; if q_sxg == 0 { Err ( anyhow ! ( " " SXG ) ) } else { match accept_filter { AcceptFilter :: PrefersSxg => { if q_sxg == 1000 { Ok ( ( ) ) } else { Err ( anyhow ! ( " " SXG ) ) } } AcceptFilter :: AcceptsSxg => Ok ( ( ) ) , } } }
Checks whether to serve SXG based on the Accept header of the HTTP request.
Checks whether to serve SXG based on the Accept header of the HTTP request .
accept
&str
accept_filter
AcceptFilter
accept
&str
accept_filter
AcceptFilter