typed_headers/impls/
authorization.rs

1use http::header::AUTHORIZATION;
2
3use super::Credentials;
4
5header! {
6    /// `Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.2)
7    ///
8    /// The `Authorization` header field allows a user agent to authenticate
9    /// itself with an origin server -- usually, but not necessarily, after
10    /// receiving a 401 (Unauthorized) response.  Its value consists of
11    /// credentials containing the authentication information of the user
12    /// agent for the realm of the resource being requested.
13    ///
14    /// # ABNF
15    ///
16    /// ```text
17    /// Authorization = credentials
18    /// ```
19    ///
20    /// # Example values
21    /// * `Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==`
22    /// * `Bearer fpKL54jvWmEGVoRdCNjG`
23    (Authorization, AUTHORIZATION) => [Credentials]
24}
25
26#[cfg(test)]
27mod test {
28    use super::*;
29    use crate::{util, Token68};
30
31    #[test]
32    fn rfc1() {
33        util::test_round_trip(
34            &Authorization(Credentials::basic("Aladdin", "open sesame").unwrap()),
35            &["Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="],
36        );
37    }
38
39    #[test]
40    fn rfc2() {
41        util::test_round_trip(
42            &Authorization(Credentials::bearer(
43                Token68::new("fpKL54jvWmEGVoRdCNjG").unwrap(),
44            )),
45            &["Bearer fpKL54jvWmEGVoRdCNjG"],
46        );
47    }
48}