refactor(header): Change to base64 serialize

Replace rustc-serialize with base64 crate.

Closes #1028
This commit is contained in:
Andy Moran
2017-01-24 01:09:14 -06:00
committed by Sean McArthur
parent 0e332c66f2
commit 529ad564c3
3 changed files with 6 additions and 10 deletions

View File

@@ -12,6 +12,7 @@ keywords = ["http", "hyper", "hyperium"]
categories = ["web-programming::http-client", "web-programming::http-server"] categories = ["web-programming::http-client", "web-programming::http-server"]
[dependencies] [dependencies]
base64 = "0.3.0"
futures = "0.1.7" futures = "0.1.7"
futures-cpupool = "0.1" futures-cpupool = "0.1"
httparse = "1.0" httparse = "1.0"
@@ -19,7 +20,6 @@ language-tags = "0.2"
log = "0.3" log = "0.3"
mime = "0.2" mime = "0.2"
relay = "0.1" relay = "0.1"
rustc-serialize = "0.3"
time = "0.1" time = "0.1"
tokio-core = "0.1" tokio-core = "0.1"
tokio-proto = "0.1" tokio-proto = "0.1"

View File

@@ -2,7 +2,7 @@ use std::any::Any;
use std::fmt::{self, Display}; use std::fmt::{self, Display};
use std::str::{FromStr, from_utf8}; use std::str::{FromStr, from_utf8};
use std::ops::{Deref, DerefMut}; use std::ops::{Deref, DerefMut};
use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline}; use base64::{encode, decode};
use header::{Header, Raw}; use header::{Header, Raw};
/// `Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.2) /// `Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.2)
@@ -152,19 +152,15 @@ impl Scheme for Basic {
if let Some(ref pass) = self.password { if let Some(ref pass) = self.password {
text.push_str(&pass[..]); text.push_str(&pass[..]);
} }
f.write_str(&text.as_bytes().to_base64(Config {
char_set: Standard, f.write_str(&encode(text.as_ref()))
newline: Newline::CRLF,
pad: true,
line_length: None
})[..])
} }
} }
impl FromStr for Basic { impl FromStr for Basic {
type Err = ::Error; type Err = ::Error;
fn from_str(s: &str) -> ::Result<Basic> { fn from_str(s: &str) -> ::Result<Basic> {
match s.from_base64() { match decode(s) {
Ok(decoded) => match String::from_utf8(decoded) { Ok(decoded) => match String::from_utf8(decoded) {
Ok(text) => { Ok(text) => {
let mut parts = &mut text.split(':'); let mut parts = &mut text.split(':');

View File

@@ -21,7 +21,7 @@ extern crate httparse;
#[macro_use] extern crate log; #[macro_use] extern crate log;
#[macro_use] pub extern crate mime; #[macro_use] pub extern crate mime;
extern crate relay; extern crate relay;
extern crate rustc_serialize as serialize; extern crate base64;
extern crate time; extern crate time;
#[macro_use] extern crate tokio_core as tokio; #[macro_use] extern crate tokio_core as tokio;
extern crate tokio_proto; extern crate tokio_proto;