    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35

    use actix_web::{
        error::ParseError,
        http::header::{Header, HeaderName, HeaderValue, TryIntoHeaderValue, WWW_AUTHENTICATE},
        HttpMessage,
    };

    use super::Challenge;

    /// `WWW-Authenticate` header, described in [RFC 7235].
    ///
    /// This header is generic over the [`Challenge`] trait, see [`Basic`](super::basic::Basic) and
    /// [`Bearer`](super::bearer::Bearer) challenges for details.
    ///
    /// [RFC 7235]: https://tools.ietf.org/html/rfc7235#section-4.1
    #[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct WwwAuthenticate<C: Challenge>(pub C);

    impl<C: Challenge> Header for WwwAuthenticate<C> {
        #[inline]
        fn name() -> HeaderName {
            WWW_AUTHENTICATE
        }

        fn parse<T: HttpMessage>(_msg: &T) -> Result<Self, ParseError> {
            unimplemented!()
        }
    }

    impl<C: Challenge> TryIntoHeaderValue for WwwAuthenticate<C> {
        type Error = <C as TryIntoHeaderValue>::Error;

        fn try_into_value(self) -> Result<HeaderValue, Self::Error> {
            self.0.try_into_value()
        }
    }