fn extract_challenge_from_headers(header: &HeaderMap) -> Result<Challenge> {
    let www_auths = header
        .get_all("WWW-Authenticate")
        .into_iter()
        .map(|val| {
            Ok(val
                .to_str()
                .context(ErrorKind::ApiMalformedHeader("WWW-Authenticate"))?
                .parse::<WWWAuthenticate>()
                .context(ErrorKind::ApiMalformedHeader("WWW-Authenticate"))?)
        })
        .collect::<Result<Vec<_>>>()?;

    if www_auths.is_empty() {
        return Err(ErrorKind::ApiMissingHeader("WWW-Authenticate").into());
    }

    trace!("Parsed WWW-Authenticate header(s): {:#?}", www_auths);

    let mut best_challenge = None;
    let mut unsupported_schemes = Vec::new();
    for challenge in www_auths
        .into_iter()
        .flat_map(|www_auth| www_auth.into_iter())
    {
        match challenge.scheme() {
            ChallengeScheme::Bearer => best_challenge = Some(challenge),
            // ... add schemes in order here ...
            _ => unsupported_schemes.push(challenge.scheme().clone()),
        }
    }
    best_challenge.ok_or_else(|| AuthError::UnsupportedAuth(unsupported_schemes).into())
}
/// Extracts the strongest implemented challenge scheme from a HeaderMap
Extracts the strongest implemented challenge scheme from a HeaderMap
Extracts the strongest implemented challenge scheme from a HeaderMap
fn extract_challenge_from_headers(header: &HeaderMap) -> Result<Challenge> {
    let www_auths = header
        .get_all("WWW-Authenticate")
        .into_iter()
        .map(|val| {
            Ok(val
                .to_str()
                .context(ErrorKind::ApiMalformedHeader("WWW-Authenticate"))?
                .parse::<WWWAuthenticate>()
                .context(ErrorKind::ApiMalformedHeader("WWW-Authenticate"))?)
        })
        .collect::<Result<Vec<_>>>()?;
    if www_auths.is_empty() {
        return Err(ErrorKind::ApiMissingHeader("WWW-Authenticate").into());
    }
    trace!("Parsed WWW-Authenticate header(s): {:#?}", www_auths);
    let mut best_challenge = None;
    let mut unsupported_schemes = Vec::new();
    for challenge in www_auths
        .into_iter()
        .flat_map(|www_auth| www_auth.into_iter())
    {
        match challenge.scheme() {
            ChallengeScheme::Bearer => best_challenge = Some(challenge),
            // ... add schemes in order here ...
            _ => unsupported_schemes.push(challenge.scheme().clone()),
        }
    }
    best_challenge.ok_or_else(|| AuthError::UnsupportedAuth(unsupported_schemes).into())
}
fn extract_challenge_from_headers ( header : & HeaderMap ) -> Result < Challenge > { let www_auths = header . get_all ( " " ) . into_iter ( ) . map ( | val | { Ok ( val . to_str ( ) . context ( ErrorKind :: ApiMalformedHeader ( " " ) ) ? . parse :: < WWWAuthenticate > ( ) . context ( ErrorKind :: ApiMalformedHeader ( " " ) ) ? ) } ) . collect :: < Result < Vec < _ > > > ( ) ? ; if www_auths . is_empty ( ) { return Err ( ErrorKind :: ApiMissingHeader ( " " ) . into ( ) ) ; } trace ! ( " " www_auths ) ; let mut best_challenge = None ; let mut unsupported_schemes = Vec :: new ( ) ; for challenge in www_auths . into_iter ( ) . flat_map ( | www_auth | www_auth . into_iter ( ) ) { match challenge . scheme ( ) { ChallengeScheme :: Bearer => best_challenge = Some ( challenge ) , // ... add schemes in order here ... _ => unsupported_schemes . push ( challenge . scheme ( ) . clone ( ) ) , } } best_challenge . ok_or_else ( | | AuthError :: UnsupportedAuth ( unsupported_schemes ) . into ( ) ) }
Extracts the strongest implemented challenge scheme from a HeaderMap
Extracts the strongest implemented challenge scheme from a HeaderMap
header
&HeaderMap
header
&HeaderMap