Skip to content

Update for latest Rust nightly #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ url = "*"
openssl = "*"
mime = "*"
unsafe-any = "*"
typeable = "*"
cookie = "*"
time = "*"
mucell = "*"
Expand Down
2 changes: 1 addition & 1 deletion benches/client_mock_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::path::BytesContainer;

use hyper::net;

static README: &'static [u8] = include_bin!("../README.md");
static README: &'static [u8] = include_bytes!("../README.md");


struct MockStream {
Expand Down
4 changes: 2 additions & 2 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ fn main() {

let mut res = match client.get(url).send() {
Ok(res) => res,
Err(err) => panic!("Failed to connect: {}", err)
Err(err) => panic!("Failed to connect: {:?}", err)
};

println!("Response: {}", res.status);
println!("Headers:\n{}", res.headers);
match copy(&mut res, &mut stdout()) {
Ok(..) => (),
Err(e) => panic!("Stream failure: {}", e)
Err(e) => panic!("Stream failure: {:?}", e)
};

}
21 changes: 11 additions & 10 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl Client<HttpConnector> {

}

#[old_impl_check]
impl<C: NetworkConnector<S>, S: NetworkStream> Client<C> {

/// Create a new client with a specific connector.
Expand Down Expand Up @@ -162,7 +163,7 @@ impl<'a, U: IntoUrl, C: NetworkConnector<S>, S: NetworkStream> RequestBuilder<'a
pub fn send(self) -> HttpResult<Response> {
let RequestBuilder { client, method, url, headers, body } = self;
let mut url = try!(url.into_url());
debug!("client.request {} {}", method, url);
debug!("client.request {:?} {:?}", method, url);

let can_have_body = match &method {
&Method::Get | &Method::Head => false,
Expand Down Expand Up @@ -193,13 +194,13 @@ impl<'a, U: IntoUrl, C: NetworkConnector<S>, S: NetworkStream> RequestBuilder<'a
if res.status.class() != Redirection {
return Ok(res)
}
debug!("redirect code {} for {}", res.status, url);
debug!("redirect code {:?} for {:?}", res.status, url);

let loc = {
// punching borrowck here
let loc = match res.headers.get::<Location>() {
Some(&Location(ref loc)) => {
Some(UrlParser::new().base_url(&url).parse(loc[]))
Some(UrlParser::new().base_url(&url).parse(&loc[]))
}
None => {
debug!("no Location header");
Expand All @@ -217,7 +218,7 @@ impl<'a, U: IntoUrl, C: NetworkConnector<S>, S: NetworkStream> RequestBuilder<'a
inspect!("Location", u)
},
Err(e) => {
debug!("Location header had invalid URI: {}", e);
debug!("Location header had invalid URI: {:?}", e);
return Ok(res);
}
};
Expand All @@ -242,13 +243,13 @@ pub enum Body<'a> {
/// A Reader does not necessarily know it's size, so it is chunked.
ChunkedBody(&'a mut (Reader + 'a)),
/// For Readers that can know their size, like a `File`.
SizedBody(&'a mut (Reader + 'a), uint),
SizedBody(&'a mut (Reader + 'a), usize),
/// A String has a size, and uses Content-Length.
BufBody(&'a [u8] , uint),
BufBody(&'a [u8] , usize),
}

impl<'a> Body<'a> {
fn size(&self) -> Option<uint> {
fn size(&self) -> Option<usize> {
match *self {
Body::SizedBody(_, len) | Body::BufBody(_, len) => Some(len),
_ => None
Expand All @@ -258,7 +259,7 @@ impl<'a> Body<'a> {

impl<'a> Reader for Body<'a> {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
match *self {
Body::ChunkedBody(ref mut r) => r.read(buf),
Body::SizedBody(ref mut r, _) => r.read(buf),
Expand Down Expand Up @@ -343,12 +344,12 @@ fn get_host_and_port(url: &Url) -> HttpResult<(String, Port)> {
Some(host) => host,
None => return Err(HttpUriError(UrlError::EmptyHost))
};
debug!("host={}", host);
debug!("host={:?}", host);
let port = match url.port_or_default() {
Some(port) => port,
None => return Err(HttpUriError(UrlError::InvalidPort))
};
debug!("port={}", port);
debug!("port={:?}", port);
Ok((host, port))
}

Expand Down
18 changes: 9 additions & 9 deletions src/client/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ impl Request<Fresh> {

/// Create a new client request with a specific underlying NetworkStream.
pub fn with_connector<C: NetworkConnector<S>, S: NetworkStream>(method: method::Method, url: Url, connector: &mut C) -> HttpResult<Request<Fresh>> {
debug!("{} {}", method, url);
debug!("{:?} {:?}", method, url);
let (host, port) = try!(get_host_and_port(&url));

let stream: S = try!(connector.connect(host[], port, &*url.scheme));
let stream: S = try!(connector.connect(&host[], port, &*url.scheme));
let stream = ThroughWriter(BufferedWriter::new(box stream as Box<NetworkStream + Send>));

let mut headers = Headers::new();
Expand Down Expand Up @@ -110,17 +110,17 @@ impl Request<Fresh> {
//TODO: this needs a test
if let Some(ref q) = self.url.query {
uri.push('?');
uri.push_str(q[]);
uri.push_str(&q[]);
}

debug!("writing head: {} {} {}", self.method, uri, self.version);
debug!("writing head: {:?} {:?} {:?}", self.method, uri, self.version);
try!(write!(&mut self.body, "{} {} {}{}",
self.method, uri, self.version, LINE_ENDING));


let stream = match self.method {
Get | Head => {
debug!("headers [\n{}]", self.headers);
debug!("headers [\n{:?}]", self.headers);
try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING));
EmptyWriter(self.body.unwrap())
},
Expand All @@ -139,7 +139,7 @@ impl Request<Fresh> {
// cant do in match above, thanks borrowck
if chunked {
let encodings = match self.headers.get_mut::<common::TransferEncoding>() {
Some(&common::TransferEncoding(ref mut encodings)) => {
Some(&mut common::TransferEncoding(ref mut encodings)) => {
//TODO: check if chunked is already in encodings. use HashSet?
encodings.push(common::transfer_encoding::Encoding::Chunked);
false
Expand All @@ -153,7 +153,7 @@ impl Request<Fresh> {
}
}

debug!("headers [\n{}]", self.headers);
debug!("headers [\n{:?}]", self.headers);
try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING));

if chunked {
Expand Down Expand Up @@ -218,7 +218,7 @@ mod tests {
let stream = *req.body.end().unwrap()
.into_inner().downcast::<MockStream>().ok().unwrap();
let bytes = stream.write.into_inner();
let s = from_utf8(bytes[]).unwrap();
let s = from_utf8(&bytes[]).unwrap();
assert!(!s.contains("Content-Length:"));
assert!(!s.contains("Transfer-Encoding:"));
}
Expand All @@ -232,7 +232,7 @@ mod tests {
let stream = *req.body.end().unwrap()
.into_inner().downcast::<MockStream>().ok().unwrap();
let bytes = stream.write.into_inner();
let s = from_utf8(bytes[]).unwrap();
let s = from_utf8(&bytes[]).unwrap();
assert!(!s.contains("Content-Length:"));
assert!(!s.contains("Transfer-Encoding:"));
}
Expand Down
8 changes: 4 additions & 4 deletions src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ impl Response {
Some(status) => status,
None => return Err(HttpStatusError)
};
debug!("{} {}", version, status);
debug!("{:?} {:?}", version, status);

let headers = try!(header::Headers::from_raw(&mut stream));
debug!("Headers: [\n{}]", headers);
debug!("Headers: [\n{:?}]", headers);

let body = if headers.has::<TransferEncoding>() {
match headers.get::<TransferEncoding>() {
Some(&TransferEncoding(ref codings)) => {
if codings.len() > 1 {
debug!("TODO: #2 handle other codings: {}", codings);
debug!("TODO: #2 handle other codings: {:?}", codings);
};

if codings.contains(&Chunked) {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl Response {

impl Reader for Response {
#[inline]
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
self.body.read(buf)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use mime;
#[derive(Clone, PartialEq, Show)]
pub struct Accept(pub Vec<shared::QualityItem<mime::Mime>>);

deref!(Accept -> Vec<shared::QualityItem<mime::Mime>>);
deref!(Accept => Vec<shared::QualityItem<mime::Mime>>);

impl header::Header for Accept {
fn header_name(_: Option<Accept>) -> &'static str {
Expand All @@ -43,7 +43,7 @@ impl header::Header for Accept {

impl header::HeaderFormat for Accept {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
shared::fmt_comma_delimited(fmt, self[])
shared::fmt_comma_delimited(fmt, &self[])
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/header/common/accept_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use header::shared;
#[derive(Clone, PartialEq, Show)]
pub struct AcceptEncoding(pub Vec<shared::QualityItem<shared::Encoding>>);

deref!(AcceptEncoding -> Vec<shared::QualityItem<shared::Encoding>>);
deref!(AcceptEncoding => Vec<shared::QualityItem<shared::Encoding>>);

impl header::Header for AcceptEncoding {
fn header_name(_: Option<AcceptEncoding>) -> &'static str {
Expand All @@ -24,7 +24,7 @@ impl header::Header for AcceptEncoding {

impl header::HeaderFormat for AcceptEncoding {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
shared::fmt_comma_delimited(fmt, self[])
shared::fmt_comma_delimited(fmt, &self[])
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/header/common/access_control/allow_origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl header::Header for AccessControlAllowOrigin {

fn parse_header(raw: &[Vec<u8>]) -> Option<AccessControlAllowOrigin> {
if raw.len() == 1 {
match str::from_utf8(unsafe { raw[].get_unchecked(0)[] }) {
match str::from_utf8(unsafe { &raw[].get_unchecked(0)[] }) {
Ok(s) => {
if s == "*" {
Some(AccessControlAllowOrigin::AllowStar)
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/allow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use header::shared::util::{from_comma_delimited, fmt_comma_delimited};
#[derive(Clone, PartialEq, Show)]
pub struct Allow(pub Vec<Method>);

deref!(Allow -> Vec<Method>);
deref!(Allow => Vec<Method>);

impl Header for Allow {
fn header_name(_: Option<Allow>) -> &'static str {
Expand All @@ -23,7 +23,7 @@ impl Header for Allow {

impl HeaderFormat for Allow {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt_comma_delimited(fmt, self[])
fmt_comma_delimited(fmt, &self[])
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/header/common/authorization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{self, Show};
use std::fmt;
use std::str::{FromStr, from_utf8};
use std::ops::{Deref, DerefMut};
use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline};
Expand Down Expand Up @@ -29,7 +29,7 @@ impl<S: Scheme> Header for Authorization<S> {

fn parse_header(raw: &[Vec<u8>]) -> Option<Authorization<S>> {
if raw.len() == 1 {
match (from_utf8(unsafe { raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) {
match (from_utf8(unsafe { &raw[].get_unchecked(0)[] }), Scheme::scheme(None::<S>)) {
(Ok(header), Some(scheme))
if header.starts_with(scheme) && header.len() > scheme.len() + 1 => {
header[scheme.len() + 1..].parse::<S>().map(|s| Authorization(s))
Expand Down Expand Up @@ -70,7 +70,7 @@ impl Scheme for String {
}

fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.fmt(f)
write!(f, "{}", self)
}
}

Expand All @@ -96,14 +96,14 @@ impl Scheme for Basic {
let mut text = self.username.clone();
text.push(':');
if let Some(ref pass) = self.password {
text.push_str(pass[]);
text.push_str(&pass[]);
}
text.as_bytes().to_base64(Config {
write!(f, "{}", text.as_bytes().to_base64(Config {
char_set: Standard,
newline: Newline::CRLF,
pad: true,
line_length: None
}).fmt(f)
}))
}
}

Expand All @@ -112,7 +112,7 @@ impl FromStr for Basic {
match s.from_base64() {
Ok(decoded) => match String::from_utf8(decoded) {
Ok(text) => {
let mut parts = text[].split(':');
let mut parts = &mut text[].split(':');
let user = match parts.next() {
Some(part) => part.to_string(),
None => return None
Expand All @@ -127,12 +127,12 @@ impl FromStr for Basic {
})
},
Err(e) => {
debug!("Basic::from_utf8 error={}", e);
debug!("Basic::from_utf8 error={:?}", e);
None
}
},
Err(e) => {
debug!("Basic::from_base64 error={}", e);
debug!("Basic::from_base64 error={:?}", e);
None
}
}
Expand All @@ -159,7 +159,7 @@ mod tests {
#[test]
fn test_raw_auth_parse() {
let headers = Headers::from_raw(&mut mem("Authorization: foo bar baz\r\n\r\n")).unwrap();
assert_eq!(headers.get::<Authorization<String>>().unwrap().0[], "foo bar baz");
assert_eq!(&headers.get::<Authorization<String>>().unwrap().0[], "foo bar baz");
}

#[test]
Expand All @@ -180,7 +180,7 @@ mod tests {
fn test_basic_auth_parse() {
let headers = Headers::from_raw(&mut mem("Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n\r\n")).unwrap();
let auth = headers.get::<Authorization<Basic>>().unwrap();
assert_eq!(auth.0.username[], "Aladdin");
assert_eq!(&auth.0.username[], "Aladdin");
assert_eq!(auth.0.password, Some("open sesame".to_string()));
}

Expand Down
Loading