refactor(headers): Improve docs, fix nits, make formatting faster

src/header/parsing.rs now uses unsafe get_unchecked() again, I don't
know why it was removed.
This commit is contained in:
Pyfisch
2015-05-03 11:21:15 +02:00
parent b916a7b18c
commit 66d54d03e7
21 changed files with 187 additions and 96 deletions

View File

@@ -1,11 +1,25 @@
use std::any::Any;
use std::fmt;
use std::fmt::{self, Display};
use std::str::{FromStr, from_utf8};
use std::ops::{Deref, DerefMut};
use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline};
use header::{Header, HeaderFormat};
/// The `Authorization` header field.
/// `Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.2)
///
/// The `Authorization` header field allows a user agent to authenticate
/// itself with an origin server -- usually, but not necessarily, after
/// receiving a 401 (Unauthorized) response. Its value consists of
/// credentials containing the authentication information of the user
/// agent for the realm of the resource being requested.
///
/// # ABNF
/// ```plain
/// Authorization = credentials
/// ```
///
/// # Example values
/// * `Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==`
#[derive(Clone, PartialEq, Debug)]
pub struct Authorization<S: Scheme>(pub S);
@@ -69,7 +83,7 @@ impl Scheme for String {
}
fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
Display::fmt(self, f)
}
}
@@ -97,12 +111,12 @@ impl Scheme for Basic {
if let Some(ref pass) = self.password {
text.push_str(&pass[..]);
}
write!(f, "{}", text.as_bytes().to_base64(Config {
f.write_str(&text.as_bytes().to_base64(Config {
char_set: Standard,
newline: Newline::CRLF,
pad: true,
line_length: None
}))
})[..])
}
}