Skip to content

Commit

Permalink
Merge pull request hyperium#227 from hyperium/rustup
Browse files Browse the repository at this point in the history
Rustup
  • Loading branch information
seanmonstar committed Jan 6, 2015
2 parents 76126fc + 23aeb49 commit b10fecb
Show file tree
Hide file tree
Showing 42 changed files with 200 additions and 179 deletions.
4 changes: 2 additions & 2 deletions benches/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extern crate hyper;

extern crate test;

use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use std::io::net::ip::Ipv4Addr;
use hyper::server::{Request, Response, Server};
use hyper::header::Headers;
Expand Down Expand Up @@ -46,7 +46,7 @@ fn bench_curl(b: &mut test::Bencher) {
listening.close().unwrap();
}

#[deriving(Clone)]
#[derive(Clone)]
struct Foo;

impl hyper::header::Header for Foo {
Expand Down
7 changes: 3 additions & 4 deletions benches/client_mock_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ extern crate hyper;

extern crate test;

use std::fmt::{mod, Show};
use std::str::from_str;
use std::fmt::{self, Show};
use std::io::{IoResult, MemReader};
use std::io::net::ip::SocketAddr;
use std::os;
Expand Down Expand Up @@ -65,7 +64,7 @@ fn bench_mock_curl(b: &mut test::Bencher) {
});
}

#[deriving(Clone)]
#[derive(Clone)]
struct Foo;

impl hyper::header::Header for Foo {
Expand All @@ -85,7 +84,7 @@ impl hyper::header::HeaderFormat for Foo {

impl net::NetworkStream for MockStream {
fn peer_name(&mut self) -> IoResult<SocketAddr> {
Ok(from_str("127.0.0.1:1337").unwrap())
Ok("127.0.0.1:1337".parse().unwrap())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl<'a> IntoUrl for &'a str {
}

/// Behavior regarding how to handle redirects within a Client.
#[deriving(Copy)]
#[derive(Copy)]
pub enum RedirectPolicy {
/// Don't follow any redirects.
FollowNone,
Expand Down
18 changes: 9 additions & 9 deletions src/client/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use url::Url;
use method;
use method::Method::{Get, Post, Delete, Put, Patch, Head, Options};
use header::Headers;
use header::common::{mod, Host};
use header::common::{self, Host};
use net::{NetworkStream, NetworkConnector, HttpConnector, Fresh, Streaming};
use http::{HttpWriter, LINE_ENDING};
use http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter, EmptyWriter};
Expand Down Expand Up @@ -114,15 +114,14 @@ impl Request<Fresh> {
}

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


let stream = match self.method {
Get | Head => {
debug!("headers [\n{}]", self.headers);
try!(write!(&mut self.body, "{}", self.headers));
try!(self.body.write(LINE_ENDING));
try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING));
EmptyWriter(self.body.unwrap())
},
_ => {
Expand Down Expand Up @@ -155,8 +154,7 @@ impl Request<Fresh> {
}

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

if chunked {
ChunkedWriter(self.body.unwrap())
Expand Down Expand Up @@ -217,7 +215,8 @@ mod tests {
Get, Url::parse("http://example.dom").unwrap(), &mut MockConnector
).unwrap();
let req = req.start().unwrap();
let stream = *req.body.end().unwrap().into_inner().downcast::<MockStream>().unwrap();
let stream = *req.body.end().unwrap()
.into_inner().downcast::<MockStream>().ok().unwrap();
let bytes = stream.write.into_inner();
let s = from_utf8(bytes[]).unwrap();
assert!(!s.contains("Content-Length:"));
Expand All @@ -230,7 +229,8 @@ mod tests {
Head, Url::parse("http://example.dom").unwrap(), &mut MockConnector
).unwrap();
let req = req.start().unwrap();
let stream = *req.body.end().unwrap().into_inner().downcast::<MockStream>().unwrap();
let stream = *req.body.end().unwrap()
.into_inner().downcast::<MockStream>().ok().unwrap();
let bytes = stream.write.into_inner();
let s = from_utf8(bytes[]).unwrap();
assert!(!s.contains("Content-Length:"));
Expand Down
2 changes: 1 addition & 1 deletion src/client/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mod tests {
status_raw: RawStatus(200, Borrowed("OK"))
};

let b = res.into_inner().downcast::<MockStream>().unwrap();
let b = res.into_inner().downcast::<MockStream>().ok().unwrap();
assert_eq!(b, box MockStream::new());

}
Expand Down
2 changes: 1 addition & 1 deletion src/header/common/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use mime;
/// qitem(Mime(Text, Html, vec![])),
/// qitem(Mime(Text, Xml, vec![])) ]));
/// ```
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct Accept(pub Vec<shared::QualityItem<mime::Mime>>);

deref!(Accept -> Vec<shared::QualityItem<mime::Mime>>);
Expand Down
2 changes: 1 addition & 1 deletion src/header/common/accept_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use header::shared;
///
/// The `Accept-Encoding` header can be used by clients to indicate what
/// response encodings they accept.
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct AcceptEncoding(pub Vec<shared::QualityItem<shared::Encoding>>);

deref!(AcceptEncoding -> Vec<shared::QualityItem<shared::Encoding>>);
Expand Down
6 changes: 3 additions & 3 deletions src/header/common/allow.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use header::{Header, HeaderFormat};
use method::Method;
use std::fmt::{mod};
use std::fmt::{self};
use header::shared::util::{from_comma_delimited, fmt_comma_delimited};

/// The `Allow` header.
/// See also https://tools.ietf.org/html/rfc7231#section-7.4.1
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct Allow(pub Vec<Method>);

deref!(Allow -> Vec<Method>);
Expand All @@ -31,7 +31,7 @@ impl HeaderFormat for Allow {
mod tests {
use super::Allow;
use header::Header;
use method::Method::{mod, Options, Get, Put, Post, Delete, Head, Trace, Connect, Patch, Extension};
use method::Method::{self, Options, Get, Put, Post, Delete, Head, Trace, Connect, Patch, Extension};

#[test]
fn test_allow() {
Expand Down
13 changes: 8 additions & 5 deletions src/header/common/authorization.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
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.
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct Authorization<S: Scheme>(pub S);

impl<S: Scheme> Deref<S> for Authorization<S> {
impl<S: Scheme> Deref for Authorization<S> {
type Target = S;

fn deref<'a>(&'a self) -> &'a S {
&self.0
}
}

impl<S: Scheme> DerefMut<S> for Authorization<S> {
impl<S: Scheme> DerefMut for Authorization<S> {
fn deref_mut<'a>(&'a mut self) -> &'a mut S {
&mut self.0
}
Expand Down Expand Up @@ -72,7 +75,7 @@ impl Scheme for String {
}

/// Credential holder for Basic Authentication
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct Basic {
/// The username as a possibly empty string
pub username: String,
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/cache_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use header::{Header, HeaderFormat};
use header::shared::util::{from_one_comma_delimited, fmt_comma_delimited};

/// The Cache-Control header.
#[deriving(PartialEq, Clone, Show)]
#[derive(PartialEq, Clone, Show)]
pub struct CacheControl(pub Vec<CacheDirective>);

deref!(CacheControl -> Vec<CacheDirective>);
Expand Down Expand Up @@ -34,7 +34,7 @@ impl HeaderFormat for CacheControl {
}

/// CacheControl contains a list of these directives.
#[deriving(PartialEq, Clone)]
#[derive(PartialEq, Clone)]
pub enum CacheDirective {
/// "no-cache"
NoCache,
Expand Down
6 changes: 3 additions & 3 deletions src/header/common/connection.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use header::{Header, HeaderFormat};
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use std::str::FromStr;
use header::shared::util::{from_comma_delimited, fmt_comma_delimited};

pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader};

/// The `Connection` header.
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct Connection(pub Vec<ConnectionOption>);

deref!(Connection -> Vec<ConnectionOption>);

/// Values that can be in the `Connection` header.
#[deriving(Clone, PartialEq)]
#[derive(Clone, PartialEq)]
pub enum ConnectionOption {
/// The `keep-alive` connection value.
KeepAlive,
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/content_length.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt::{mod, Show};
use std::fmt::{self, Show};

use header::{Header, HeaderFormat};
use header::shared::util::from_one_raw_str;

/// The `Content-Length` header.
///
/// Simply a wrapper around a `uint`.
#[deriving(Copy, Clone, PartialEq, Show)]
#[derive(Copy, Clone, PartialEq, Show)]
pub struct ContentLength(pub uint);

deref!(ContentLength -> uint);
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/content_type.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use header::{Header, HeaderFormat};
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use header::shared::util::from_one_raw_str;
use mime::Mime;

/// The `Content-Type` header.
///
/// Used to describe the MIME type of message body. Can be used with both
/// requests and responses.
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct ContentType(pub Mime);

deref!(ContentType -> Mime);
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/cookie.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use header::{Header, HeaderFormat};
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use std::str::from_utf8;

use cookie::Cookie;
Expand All @@ -13,7 +13,7 @@ use cookie::CookieJar;
///
/// > When the user agent generates an HTTP request, the user agent MUST NOT
/// > attach more than one Cookie header field.
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct Cookies(pub Vec<Cookie>);

//TODO: remove when fixed in libstd
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/date.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use std::str::FromStr;
use time::Tm;
use header::{Header, HeaderFormat};
Expand All @@ -7,7 +7,7 @@ use header::shared::time::tm_from_str;

// Egh, replace as soon as something better than time::Tm exists.
/// The `Date` header field.
#[deriving(Copy, PartialEq, Clone)]
#[derive(Copy, PartialEq, Clone)]
pub struct Date(pub Tm);

deref!(Date -> Tm);
Expand Down
6 changes: 3 additions & 3 deletions src/header/common/etag.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use header::{Header, HeaderFormat};
use std::fmt::{mod};
use std::fmt::{self};
use header::shared::util::from_one_raw_str;

/// The `Etag` header.
Expand All @@ -8,7 +8,7 @@ use header::shared::util::from_one_raw_str;
/// Preceding the first double quote is an optional weakness indicator,
/// which always looks like this: W/
/// See also: https://tools.ietf.org/html/rfc7232#section-2.3
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct Etag {
/// Weakness indicator for the tag
pub weak: bool,
Expand Down Expand Up @@ -81,7 +81,7 @@ impl Header for Etag {
impl HeaderFormat for Etag {
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
if self.weak {
try!(fmt.write(b"W/"));
try!(fmt.write_str("W/"));
}
write!(fmt, "\"{}\"", self.tag)
}
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/expires.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use std::str::FromStr;
use time::Tm;
use header::{Header, HeaderFormat};
use header::shared::util::from_one_raw_str;
use header::shared::time::tm_from_str;

/// The `Expires` header field.
#[deriving(Copy, PartialEq, Clone)]
#[derive(Copy, PartialEq, Clone)]
pub struct Expires(pub Tm);

deref!(Expires -> Tm);
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/host.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use header::{Header, HeaderFormat};
use Port;
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use header::shared::util::from_one_raw_str;

/// The `Host` header.
Expand All @@ -10,7 +10,7 @@ use header::shared::util::from_one_raw_str;
///
/// Currently is just a String, but it should probably become a better type,
/// like url::Host or something.
#[deriving(Clone, PartialEq, Show)]
#[derive(Clone, PartialEq, Show)]
pub struct Host {
/// The hostname, such a example.domain.
pub hostname: String,
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/if_modified_since.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use std::str::FromStr;
use time::Tm;
use header::{Header, HeaderFormat};
use header::shared::util::from_one_raw_str;
use header::shared::time::tm_from_str;

/// The `If-Modified-Since` header field.
#[deriving(Copy, PartialEq, Clone)]
#[derive(Copy, PartialEq, Clone)]
pub struct IfModifiedSince(pub Tm);

deref!(IfModifiedSince -> Tm);
Expand Down
4 changes: 2 additions & 2 deletions src/header/common/last_modified.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::fmt::{mod, Show};
use std::fmt::{self, Show};
use std::str::FromStr;
use time::Tm;
use header::{Header, HeaderFormat};
use header::shared::util::from_one_raw_str;
use header::shared::time::tm_from_str;

/// The `LastModified` header field.
#[deriving(Copy, PartialEq, Clone)]
#[derive(Copy, PartialEq, Clone)]
pub struct LastModified(pub Tm);

deref!(LastModified -> Tm);
Expand Down
Loading

0 comments on commit b10fecb

Please sign in to comment.