headers/common/proxy_authorization.rs
1use super::authorization::{Authorization, Credentials};
2
3/// `Proxy-Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.4)
4///
5/// The `Proxy-Authorization` header field allows a user agent to authenticate
6/// itself with an HTTP proxy -- usually, but not necessarily, after
7/// receiving a 407 (Proxy Authentication Required) response and the
8/// `Proxy-Authenticate` header. Its value consists of credentials containing
9/// the authentication information of the user agent for the realm of the
10/// resource being requested.
11///
12/// # ABNF
13///
14/// ```text
15/// Proxy-Authorization = credentials
16/// ```
17///
18/// # Example values
19/// * `Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==`
20/// * `Bearer fpKL54jvWmEGVoRdCNjG`
21///
22/// # Examples
23///
24#[derive(Clone, PartialEq, Debug)]
25pub struct ProxyAuthorization<C: Credentials>(pub C);
26
27impl<C: Credentials> ::Header for ProxyAuthorization<C> {
28 fn name() -> &'static ::HeaderName {
29 &::http::header::PROXY_AUTHORIZATION
30 }
31
32 fn decode<'i, I: Iterator<Item = &'i ::HeaderValue>>(values: &mut I) -> Result<Self, ::Error> {
33 Authorization::decode(values).map(|auth| ProxyAuthorization(auth.0))
34 }
35
36 fn encode<E: Extend<::HeaderValue>>(&self, values: &mut E) {
37 let value = self.0.encode();
38 debug_assert!(
39 value.as_bytes().starts_with(C::SCHEME.as_bytes()),
40 "Credentials::encode should include its scheme: scheme = {:?}, encoded = {:?}",
41 C::SCHEME,
42 value,
43 );
44
45 values.extend(::std::iter::once(value));
46 }
47}