fix(rustup): update to rust beta

This commit is contained in:
Sean McArthur
2015-04-02 12:32:46 -07:00
parent b4aeeb347c
commit 0f5858f379
12 changed files with 79 additions and 74 deletions

View File

@@ -171,7 +171,7 @@ mod tests {
None => panic!("Transfer-Encoding: chunked expected!"), None => panic!("Transfer-Encoding: chunked expected!"),
}; };
// The body is correct? // The body is correct?
assert_eq!(read_to_string(res), Ok("qwert".to_string())); assert_eq!(read_to_string(res).unwrap(), "qwert".to_string());
} }
/// Tests that when a chunk size is not a valid radix-16 number, an error /// Tests that when a chunk size is not a valid radix-16 number, an error
@@ -228,6 +228,6 @@ mod tests {
let res = Response::new(Box::new(stream)).unwrap(); let res = Response::new(Box::new(stream)).unwrap();
assert_eq!(read_to_string(res), Ok("1".to_string())); assert_eq!(read_to_string(res).unwrap(), "1".to_string());
} }
} }

View File

@@ -1,5 +1,5 @@
//! HttpError and HttpResult module. //! HttpError and HttpResult module.
use std::error::{Error, FromError}; use std::error::Error;
use std::fmt; use std::fmt;
use std::io::Error as IoError; use std::io::Error as IoError;
@@ -15,7 +15,7 @@ use self::HttpError::{HttpMethodError, HttpUriError, HttpVersionError,
pub type HttpResult<T> = Result<T, HttpError>; pub type HttpResult<T> = Result<T, HttpError>;
/// A set of errors that can occur parsing HTTP streams. /// A set of errors that can occur parsing HTTP streams.
#[derive(Debug, PartialEq, Clone)] #[derive(Debug)]
pub enum HttpError { pub enum HttpError {
/// An invalid `Method`, such as `GE,T`. /// An invalid `Method`, such as `GE,T`.
HttpMethodError, HttpMethodError,
@@ -61,20 +61,20 @@ impl Error for HttpError {
} }
} }
impl FromError<IoError> for HttpError { impl From<IoError> for HttpError {
fn from_error(err: IoError) -> HttpError { fn from(err: IoError) -> HttpError {
HttpIoError(err) HttpIoError(err)
} }
} }
impl FromError<url::ParseError> for HttpError { impl From<url::ParseError> for HttpError {
fn from_error(err: url::ParseError) -> HttpError { fn from(err: url::ParseError) -> HttpError {
HttpUriError(err) HttpUriError(err)
} }
} }
impl FromError<httparse::Error> for HttpError { impl From<httparse::Error> for HttpError {
fn from_error(err: httparse::Error) -> HttpError { fn from(err: httparse::Error) -> HttpError {
match err { match err {
httparse::Error::HeaderName => HttpHeaderError, httparse::Error::HeaderName => HttpHeaderError,
httparse::Error::HeaderValue => HttpHeaderError, httparse::Error::HeaderValue => HttpHeaderError,

View File

@@ -1,4 +1,7 @@
use std::fmt; use std::fmt;
use std::str;
use unicase::UniCase;
use header::{Header, HeaderFormat}; use header::{Header, HeaderFormat};
@@ -16,14 +19,29 @@ pub enum Expect {
Continue Continue
} }
const EXPECT_CONTINUE: UniCase<&'static str> = UniCase("100-continue");
impl Header for Expect { impl Header for Expect {
fn header_name() -> &'static str { fn header_name() -> &'static str {
"Expect" "Expect"
} }
fn parse_header(raw: &[Vec<u8>]) -> Option<Expect> { fn parse_header(raw: &[Vec<u8>]) -> Option<Expect> {
if &[b"100-continue"] == raw { if raw.len() == 1 {
Some(Expect::Continue) let text = unsafe {
// safe because:
// 1. we just checked raw.len == 1
// 2. we don't actually care if it's utf8, we just want to
// compare the bytes with the "case" normalized. If it's not
// utf8, then the byte comparison will fail, and we'll return
// None. No big deal.
str::from_utf8_unchecked(raw.get_unchecked(0))
};
if UniCase(text) == EXPECT_CONTINUE {
Some(Expect::Continue)
} else {
None
}
} else { } else {
None None
} }

View File

@@ -141,11 +141,11 @@ mod tests {
#[test] #[test]
fn test_etag_parse_success() { fn test_etag_parse_success() {
// Expected success // Expected success
assert_eq!("\"foobar\"".parse().unwrap(), EntityTag::new(false, "foobar".to_string())); assert_eq!("\"foobar\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "foobar".to_string()));
assert_eq!("\"\"".parse().unwrap(), EntityTag::new(false, "".to_string())); assert_eq!("\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "".to_string()));
assert_eq!("W/\"weaktag\"".parse().unwrap(), EntityTag::new(true, "weaktag".to_string())); assert_eq!("W/\"weaktag\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "weaktag".to_string()));
assert_eq!("W/\"\x65\x62\"".parse().unwrap(), EntityTag::new(true, "\x65\x62".to_string())); assert_eq!("W/\"\x65\x62\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "\x65\x62".to_string()));
assert_eq!("W/\"\"".parse().unwrap(), EntityTag::new(true, "".to_string())); assert_eq!("W/\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "".to_string()));
} }
#[test] #[test]

View File

@@ -114,7 +114,7 @@ impl<T: str::FromStr> str::FromStr for QualityItem<T> {
let mut raw_item = s; let mut raw_item = s;
let mut quality = 1f32; let mut quality = 1f32;
let parts: Vec<&str> = s.rsplitn(1, ';').map(|x| x.trim()).collect(); let parts: Vec<&str> = s.rsplitn(2, ';').map(|x| x.trim()).collect();
if parts.len() == 2 { if parts.len() == 2 {
let start = &parts[0][0..2]; let start = &parts[0][0..2];
if start == "q=" || start == "Q=" { if start == "q=" || start == "Q=" {

View File

@@ -120,8 +120,7 @@ fn eat<R: Read>(rdr: &mut R, bytes: &[u8]) -> io::Result<()> {
match try!(rdr.read(&mut buf)) { match try!(rdr.read(&mut buf)) {
1 if buf[0] == b => (), 1 if buf[0] == b => (),
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput, _ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Invalid characters found", "Invalid characters found")),
None))
} }
} }
Ok(()) Ok(())
@@ -135,8 +134,7 @@ fn read_chunk_size<R: Read>(rdr: &mut R) -> io::Result<u64> {
match try!($rdr.read(&mut buf)) { match try!($rdr.read(&mut buf)) {
1 => buf[0], 1 => buf[0],
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput, _ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Invalid chunk size line", "Invalid chunk size line")),
None)),
} }
}) })
@@ -163,8 +161,7 @@ fn read_chunk_size<R: Read>(rdr: &mut R) -> io::Result<u64> {
match byte!(rdr) { match byte!(rdr) {
LF => break, LF => break,
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput, _ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Invalid chunk size line", "Invalid chunk size line"))
None))
} }
}, },
@@ -190,8 +187,7 @@ fn read_chunk_size<R: Read>(rdr: &mut R) -> io::Result<u64> {
// other octet, the chunk size line is invalid! // other octet, the chunk size line is invalid!
_ => { _ => {
return Err(io::Error::new(io::ErrorKind::InvalidInput, return Err(io::Error::new(io::ErrorKind::InvalidInput,
"Invalid chunk size line", "Invalid chunk size line"));
None))
} }
} }
} }
@@ -441,7 +437,7 @@ mod tests {
use std::str::from_utf8; use std::str::from_utf8;
let mut w = super::HttpWriter::SizedWriter(Vec::new(), 8); let mut w = super::HttpWriter::SizedWriter(Vec::new(), 8);
w.write_all(b"foo bar").unwrap(); w.write_all(b"foo bar").unwrap();
assert_eq!(w.write(b"baz"), Ok(1)); assert_eq!(w.write(b"baz").unwrap(), 1);
let buf = w.end().unwrap(); let buf = w.end().unwrap();
let s = from_utf8(buf.as_ref()).unwrap(); let s = from_utf8(buf.as_ref()).unwrap();
@@ -450,22 +446,22 @@ mod tests {
#[test] #[test]
fn test_read_chunk_size() { fn test_read_chunk_size() {
fn read(s: &str, result: io::Result<u64>) { fn read(s: &str, result: u64) {
assert_eq!(read_chunk_size(&mut s.as_bytes()), result); assert_eq!(read_chunk_size(&mut s.as_bytes()).unwrap(), result);
} }
fn read_err(s: &str) { fn read_err(s: &str) {
assert_eq!(read_chunk_size(&mut s.as_bytes()).unwrap_err().kind(), io::ErrorKind::InvalidInput); assert_eq!(read_chunk_size(&mut s.as_bytes()).unwrap_err().kind(), io::ErrorKind::InvalidInput);
} }
read("1\r\n", Ok(1)); read("1\r\n", 1);
read("01\r\n", Ok(1)); read("01\r\n", 1);
read("0\r\n", Ok(0)); read("0\r\n", 0);
read("00\r\n", Ok(0)); read("00\r\n", 0);
read("A\r\n", Ok(10)); read("A\r\n", 10);
read("a\r\n", Ok(10)); read("a\r\n", 10);
read("Ff\r\n", Ok(255)); read("Ff\r\n", 255);
read("Ff \r\n", Ok(255)); read("Ff \r\n", 255);
// Missing LF or CRLF // Missing LF or CRLF
read_err("F\rF"); read_err("F\rF");
read_err("F"); read_err("F");
@@ -475,14 +471,14 @@ mod tests {
read_err("-\r\n"); read_err("-\r\n");
read_err("-1\r\n"); read_err("-1\r\n");
// Acceptable (if not fully valid) extensions do not influence the size // Acceptable (if not fully valid) extensions do not influence the size
read("1;extension\r\n", Ok(1)); read("1;extension\r\n", 1);
read("a;ext name=value\r\n", Ok(10)); read("a;ext name=value\r\n", 10);
read("1;extension;extension2\r\n", Ok(1)); read("1;extension;extension2\r\n", 1);
read("1;;; ;\r\n", Ok(1)); read("1;;; ;\r\n", 1);
read("2; extension...\r\n", Ok(2)); read("2; extension...\r\n", 2);
read("3 ; extension=123\r\n", Ok(3)); read("3 ; extension=123\r\n", 3);
read("3 ;\r\n", Ok(3)); read("3 ;\r\n", 3);
read("3 ; \r\n", Ok(3)); read("3 ; \r\n", 3);
// Invalid extensions cause an error // Invalid extensions cause an error
read_err("1 invalid extension\r\n"); read_err("1 invalid extension\r\n");
read_err("1 A\r\n"); read_err("1 A\r\n");

View File

@@ -1,5 +1,5 @@
#![doc(html_root_url = "https://hyperium.github.io/hyper/hyper/index.html")] #![doc(html_root_url = "https://hyperium.github.io/hyper/hyper/index.html")]
#![feature(core, io, unsafe_destructor, into_cow, convert)] #![feature(core, into_cow)]
#![deny(missing_docs)] #![deny(missing_docs)]
#![cfg_attr(test, deny(warnings))] #![cfg_attr(test, deny(warnings))]
#![cfg_attr(test, feature(test))] #![cfg_attr(test, feature(test))]

View File

@@ -129,9 +129,9 @@ mod tests {
#[test] #[test]
fn test_from_str() { fn test_from_str() {
assert_eq!(Ok(Get), FromStr::from_str("GET")); assert_eq!(Get, FromStr::from_str("GET").unwrap());
assert_eq!(Ok(Extension("MOVE".to_string())), assert_eq!(Extension("MOVE".to_string()),
FromStr::from_str("MOVE")); FromStr::from_str("MOVE").unwrap());
} }
#[test] #[test]

View File

@@ -202,10 +202,9 @@ impl NetworkListener for HttpListener {
let stream = CloneTcpStream(try!(tcp.accept()).0); let stream = CloneTcpStream(try!(tcp.accept()).0);
match SslStream::new_server(&**ssl_context, stream) { match SslStream::new_server(&**ssl_context, stream) {
Ok(ssl_stream) => HttpStream::Https(ssl_stream), Ok(ssl_stream) => HttpStream::Https(ssl_stream),
Err(StreamError(ref e)) => { Err(StreamError(e)) => {
return Err(io::Error::new(io::ErrorKind::ConnectionAborted, return Err(io::Error::new(io::ErrorKind::ConnectionAborted,
"SSL Handshake Interrupted", e));
Some(e.to_string())));
}, },
Err(e) => return Err(lift_ssl_error(e)) Err(e) => return Err(lift_ssl_error(e))
} }
@@ -326,8 +325,7 @@ impl<'v> NetworkConnector for HttpConnector<'v> {
}, },
_ => { _ => {
Err(io::Error::new(io::ErrorKind::InvalidInput, Err(io::Error::new(io::ErrorKind::InvalidInput,
"Invalid scheme for Http", "Invalid scheme for Http"))
None))
} }
} }
} }
@@ -338,13 +336,8 @@ fn lift_ssl_error(ssl: SslError) -> io::Error {
match ssl { match ssl {
StreamError(err) => err, StreamError(err) => err,
SslSessionClosed => io::Error::new(io::ErrorKind::ConnectionAborted, SslSessionClosed => io::Error::new(io::ErrorKind::ConnectionAborted,
"SSL Connection Closed", "SSL Connection Closed"),
None), e@OpenSslErrors(..) => io::Error::new(io::ErrorKind::Other, e)
// Unfortunately throw this away. No way to support this
// detail without a better Error abstraction.
OpenSslErrors(errs) => io::Error::new(io::ErrorKind::Other,
"Error in OpenSSL",
Some(format!("{:?}", errs)))
} }
} }

View File

@@ -73,7 +73,6 @@ impl<T: Send + 'static> Sentinel<T> {
//fn cancel(mut self) { self.active = false; } //fn cancel(mut self) { self.active = false; }
} }
#[unsafe_destructor]
impl<T: Send + 'static> Drop for Sentinel<T> { impl<T: Send + 'static> Drop for Sentinel<T> {
fn drop(&mut self) { fn drop(&mut self) {
// If we were cancelled, get out of here. // If we were cancelled, get out of here.

View File

@@ -115,7 +115,7 @@ mod tests {
let mut stream = BufReader::new(mock); let mut stream = BufReader::new(mock);
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap(); let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
assert_eq!(read_to_string(req), Ok("".to_string())); assert_eq!(read_to_string(req).unwrap(), "".to_string());
} }
#[test] #[test]
@@ -132,7 +132,7 @@ mod tests {
let mut stream = BufReader::new(mock); let mut stream = BufReader::new(mock);
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap(); let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
assert_eq!(read_to_string(req), Ok("".to_string())); assert_eq!(read_to_string(req).unwrap(), "".to_string());
} }
#[test] #[test]
@@ -149,7 +149,7 @@ mod tests {
let mut stream = BufReader::new(mock); let mut stream = BufReader::new(mock);
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap(); let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
assert_eq!(read_to_string(req), Ok("".to_string())); assert_eq!(read_to_string(req).unwrap(), "".to_string());
} }
#[test] #[test]
@@ -190,7 +190,7 @@ mod tests {
None => panic!("Transfer-Encoding: chunked expected!"), None => panic!("Transfer-Encoding: chunked expected!"),
}; };
// The content is correctly read? // The content is correctly read?
assert_eq!(read_to_string(req), Ok("qwert".to_string())); assert_eq!(read_to_string(req).unwrap(), "qwert".to_string());
} }
/// Tests that when a chunk size is not a valid radix-16 number, an error /// Tests that when a chunk size is not a valid radix-16 number, an error
@@ -262,7 +262,7 @@ mod tests {
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap(); let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
assert_eq!(read_to_string(req), Ok("1".to_string())); assert_eq!(read_to_string(req).unwrap(), "1".to_string());
} }
} }

View File

@@ -74,15 +74,14 @@ impl FromStr for RequestUri {
#[test] #[test]
fn test_uri_fromstr() { fn test_uri_fromstr() {
use error::HttpResult; fn read(s: &str, result: RequestUri) {
fn read(s: &str, result: HttpResult<RequestUri>) { assert_eq!(s.parse::<RequestUri>().unwrap(), result);
assert_eq!(s.parse(), result);
} }
read("*", Ok(RequestUri::Star)); read("*", RequestUri::Star);
read("http://hyper.rs/", Ok(RequestUri::AbsoluteUri(Url::parse("http://hyper.rs/").unwrap()))); read("http://hyper.rs/", RequestUri::AbsoluteUri(Url::parse("http://hyper.rs/").unwrap()));
read("hyper.rs", Ok(RequestUri::Authority("hyper.rs".to_string()))); read("hyper.rs", RequestUri::Authority("hyper.rs".to_string()));
read("/", Ok(RequestUri::AbsolutePath("/".to_string()))); read("/", RequestUri::AbsolutePath("/".to_string()));
} }