Skip to content

Commit 95f1786

Browse files
committed
Merge pull request #236 from hyperium/rustup
Rust up for nightly
2 parents 5a5ef10 + f7124bb commit 95f1786

24 files changed

+229
-359
lines changed

Cargo.toml

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ authors = ["Sean McArthur <[email protected]>",
1111
"Jonathan Reem <[email protected]>"]
1212

1313
[dependencies]
14-
url = "*"
15-
openssl = "*"
16-
mime = "*"
17-
unsafe-any = "*"
1814
cookie = "*"
19-
time = "*"
20-
mucell = "*"
2115
log = "*"
16+
mime = "*"
17+
mucell = "*"
18+
openssl = "*"
2219
rustc-serialize = "*"
23-
24-
[dev-dependencies]
25-
curl = "*"
26-
20+
time = "*"
21+
unicase = "*"
22+
unsafe-any = "*"
23+
url = "*"

benches/client.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![feature(macro_rules)]
2-
extern crate curl;
1+
#![allow(unstable)]
32
extern crate hyper;
43

54
extern crate test;
@@ -31,21 +30,6 @@ fn handle(_r: Request, res: Response) {
3130
try_return!(res.end());
3231
}
3332

34-
#[bench]
35-
fn bench_curl(b: &mut test::Bencher) {
36-
let mut listening = listen();
37-
let s = format!("http://{}/", listening.socket);
38-
let url = s.as_slice();
39-
b.iter(|| {
40-
curl::http::handle()
41-
.get(url)
42-
.header("X-Foo", "Bar")
43-
.exec()
44-
.unwrap()
45-
});
46-
listening.close().unwrap();
47-
}
48-
4933
#[derive(Clone)]
5034
struct Foo;
5135

benches/client_mock_tcp.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![feature(default_type_params)]
2-
extern crate curl;
1+
#![allow(unstable)]
32
extern crate hyper;
43

54
extern crate test;
@@ -49,21 +48,6 @@ impl Writer for MockStream {
4948
}
5049
}
5150

52-
#[bench]
53-
fn bench_mock_curl(b: &mut test::Bencher) {
54-
let mut cwd = os::getcwd().unwrap();
55-
cwd.push("README.md");
56-
let s = format!("file://{}", cwd.container_as_str().unwrap());
57-
let url = s.as_slice();
58-
b.iter(|| {
59-
curl::http::handle()
60-
.get(url)
61-
.header("X-Foo", "Bar")
62-
.exec()
63-
.unwrap()
64-
});
65-
}
66-
6751
#[derive(Clone)]
6852
struct Foo;
6953

@@ -90,7 +74,8 @@ impl net::NetworkStream for MockStream {
9074

9175
struct MockConnector;
9276

93-
impl net::NetworkConnector<MockStream> for MockConnector {
77+
impl net::NetworkConnector for MockConnector {
78+
type Stream = MockStream;
9479
fn connect(&mut self, _: &str, _: u16, _: &str) -> IoResult<MockStream> {
9580
Ok(MockStream::new())
9681
}

benches/server.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unstable)]
12
extern crate hyper;
23
extern crate test;
34

examples/client.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unstable)]
12
extern crate hyper;
23

34
use std::os;

examples/hello.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unstable)]
12
extern crate hyper;
23

34
use std::io::net::ip::Ipv4Addr;

examples/server.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(unstable)]
12
extern crate hyper;
23
#[macro_use] extern crate log;
34

@@ -24,7 +25,7 @@ fn echo(mut req: Request, mut res: Response) {
2425
(&Get, "/") | (&Get, "/echo") => {
2526
let out = b"Try POST /echo";
2627

27-
res.headers_mut().set(ContentLength(out.len()));
28+
res.headers_mut().set(ContentLength(out.len() as u64));
2829
let mut res = try_return!(res.start());
2930
try_return!(res.write(out));
3031
try_return!(res.end());

src/client/mod.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use openssl::ssl::VerifyCallback;
3030
use header::{Headers, Header, HeaderFormat};
3131
use header::common::{ContentLength, Location};
3232
use method::Method;
33-
use net::{NetworkConnector, NetworkStream, HttpConnector};
33+
use net::{NetworkConnector, HttpConnector};
3434
use status::StatusClass::Redirection;
3535
use {Url, Port, HttpResult};
3636
use HttpError::HttpUriError;
@@ -63,8 +63,7 @@ impl Client<HttpConnector> {
6363

6464
}
6565

66-
#[old_impl_check]
67-
impl<C: NetworkConnector<S>, S: NetworkStream> Client<C> {
66+
impl<C: NetworkConnector> Client<C> {
6867

6968
/// Create a new client with a specific connector.
7069
pub fn with_connector(connector: C) -> Client<C> {
@@ -80,33 +79,33 @@ impl<C: NetworkConnector<S>, S: NetworkStream> Client<C> {
8079
}
8180

8281
/// Execute a Get request.
83-
pub fn get<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
82+
pub fn get<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
8483
self.request(Method::Get, url)
8584
}
8685

8786
/// Execute a Head request.
88-
pub fn head<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
87+
pub fn head<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
8988
self.request(Method::Head, url)
9089
}
9190

9291
/// Execute a Post request.
93-
pub fn post<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
92+
pub fn post<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
9493
self.request(Method::Post, url)
9594
}
9695

9796
/// Execute a Put request.
98-
pub fn put<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
97+
pub fn put<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
9998
self.request(Method::Put, url)
10099
}
101100

102101
/// Execute a Delete request.
103-
pub fn delete<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C, S> {
102+
pub fn delete<U: IntoUrl>(&mut self, url: U) -> RequestBuilder<U, C> {
104103
self.request(Method::Delete, url)
105104
}
106105

107106

108107
/// Build a new request using this Client.
109-
pub fn request<U: IntoUrl>(&mut self, method: Method, url: U) -> RequestBuilder<U, C, S> {
108+
pub fn request<U: IntoUrl>(&mut self, method: Method, url: U) -> RequestBuilder<U, C> {
110109
RequestBuilder {
111110
client: self,
112111
method: method,
@@ -121,30 +120,30 @@ impl<C: NetworkConnector<S>, S: NetworkStream> Client<C> {
121120
///
122121
/// One of these will be built for you if you use one of the convenience
123122
/// methods, such as `get()`, `post()`, etc.
124-
pub struct RequestBuilder<'a, U: IntoUrl, C: NetworkConnector<S> + 'a, S: NetworkStream> {
123+
pub struct RequestBuilder<'a, U: IntoUrl, C: NetworkConnector + 'a> {
125124
client: &'a mut Client<C>,
126125
url: U,
127126
headers: Option<Headers>,
128127
method: Method,
129128
body: Option<Body<'a>>,
130129
}
131130

132-
impl<'a, U: IntoUrl, C: NetworkConnector<S>, S: NetworkStream> RequestBuilder<'a, U, C, S> {
131+
impl<'a, U: IntoUrl, C: NetworkConnector> RequestBuilder<'a, U, C> {
133132

134133
/// Set a request body to be sent.
135-
pub fn body<B: IntoBody<'a>>(mut self, body: B) -> RequestBuilder<'a, U, C, S> {
134+
pub fn body<B: IntoBody<'a>>(mut self, body: B) -> RequestBuilder<'a, U, C> {
136135
self.body = Some(body.into_body());
137136
self
138137
}
139138

140139
/// Add additional headers to the request.
141-
pub fn headers(mut self, headers: Headers) -> RequestBuilder<'a, U, C, S> {
140+
pub fn headers(mut self, headers: Headers) -> RequestBuilder<'a, U, C> {
142141
self.headers = Some(headers);
143142
self
144143
}
145144

146145
/// Add an individual new header to the request.
147-
pub fn header<H: Header + HeaderFormat>(mut self, header: H) -> RequestBuilder<'a, U, C, S> {
146+
pub fn header<H: Header + HeaderFormat>(mut self, header: H) -> RequestBuilder<'a, U, C> {
148147
{
149148
let mut headers = match self.headers {
150149
Some(ref mut h) => h,
@@ -243,15 +242,16 @@ pub enum Body<'a> {
243242
/// A Reader does not necessarily know it's size, so it is chunked.
244243
ChunkedBody(&'a mut (Reader + 'a)),
245244
/// For Readers that can know their size, like a `File`.
246-
SizedBody(&'a mut (Reader + 'a), usize),
245+
SizedBody(&'a mut (Reader + 'a), u64),
247246
/// A String has a size, and uses Content-Length.
248247
BufBody(&'a [u8] , usize),
249248
}
250249

251250
impl<'a> Body<'a> {
252-
fn size(&self) -> Option<usize> {
251+
fn size(&self) -> Option<u64> {
253252
match *self {
254-
Body::SizedBody(_, len) | Body::BufBody(_, len) => Some(len),
253+
Body::SizedBody(_, len) => Some(len),
254+
Body::BufBody(_, len) => Some(len as u64),
255255
_ => None
256256
}
257257
}

src/client/request.rs

+8-41
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ use std::io::{BufferedWriter, IoResult};
33

44
use url::Url;
55

6-
use method;
7-
use method::Method::{Get, Post, Delete, Put, Patch, Head, Options};
6+
use method::{self, Method};
87
use header::Headers;
98
use header::common::{self, Host};
109
use net::{NetworkStream, NetworkConnector, HttpConnector, Fresh, Streaming};
@@ -46,11 +45,14 @@ impl Request<Fresh> {
4645
}
4746

4847
/// Create a new client request with a specific underlying NetworkStream.
49-
pub fn with_connector<C: NetworkConnector<S>, S: NetworkStream>(method: method::Method, url: Url, connector: &mut C) -> HttpResult<Request<Fresh>> {
50-
debug!("{:?} {:?}", method, url);
48+
pub fn with_connector<C, S>(method: method::Method, url: Url, connector: &mut C)
49+
-> HttpResult<Request<Fresh>> where
50+
C: NetworkConnector<Stream=S>,
51+
S: NetworkStream + Send {
52+
debug!("{} {}", method, url);
5153
let (host, port) = try!(get_host_and_port(&url));
5254

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

5658
let mut headers = Headers::new();
@@ -68,41 +70,6 @@ impl Request<Fresh> {
6870
})
6971
}
7072

71-
/// Create a new GET request.
72-
#[inline]
73-
#[deprecated = "use hyper::Client"]
74-
pub fn get(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Get, url) }
75-
76-
/// Create a new POST request.
77-
#[inline]
78-
#[deprecated = "use hyper::Client"]
79-
pub fn post(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Post, url) }
80-
81-
/// Create a new DELETE request.
82-
#[inline]
83-
#[deprecated = "use hyper::Client"]
84-
pub fn delete(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Delete, url) }
85-
86-
/// Create a new PUT request.
87-
#[inline]
88-
#[deprecated = "use hyper::Client"]
89-
pub fn put(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Put, url) }
90-
91-
/// Create a new PATCH request.
92-
#[inline]
93-
#[deprecated = "use hyper::Client"]
94-
pub fn patch(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Patch, url) }
95-
96-
/// Create a new HEAD request.
97-
#[inline]
98-
#[deprecated = "use hyper::Client"]
99-
pub fn head(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Head, url) }
100-
101-
/// Create a new OPTIONS request.
102-
#[inline]
103-
#[deprecated = "use hyper::Client"]
104-
pub fn options(url: Url) -> HttpResult<Request<Fresh>> { Request::new(Options, url) }
105-
10673
/// Consume a Fresh Request, writing the headers and method,
10774
/// returning a Streaming Request.
10875
pub fn start(mut self) -> HttpResult<Request<Streaming>> {
@@ -119,7 +86,7 @@ impl Request<Fresh> {
11986

12087

12188
let stream = match self.method {
122-
Get | Head => {
89+
Method::Get | Method::Head => {
12390
debug!("headers [\n{:?}]", self.headers);
12491
try!(write!(&mut self.body, "{}{}", self.headers, LINE_ENDING));
12592
EmptyWriter(self.body.unwrap())

src/header/common/cache_control.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl HeaderFormat for CacheControl {
3434
}
3535

3636
/// CacheControl contains a list of these directives.
37-
#[derive(PartialEq, Clone)]
37+
#[derive(PartialEq, Clone, Show)]
3838
pub enum CacheDirective {
3939
/// "no-cache"
4040
NoCache,
@@ -47,11 +47,11 @@ pub enum CacheDirective {
4747

4848
// request directives
4949
/// "max-age=delta"
50-
MaxAge(usize),
50+
MaxAge(u32),
5151
/// "max-stale=delta"
52-
MaxStale(usize),
52+
MaxStale(u32),
5353
/// "min-fresh=delta"
54-
MinFresh(usize),
54+
MinFresh(u32),
5555

5656
// response directives
5757
/// "must-revalidate"
@@ -63,7 +63,7 @@ pub enum CacheDirective {
6363
/// "proxy-revalidate"
6464
ProxyRevalidate,
6565
/// "s-maxage=delta"
66-
SMaxAge(usize),
66+
SMaxAge(u32),
6767

6868
/// Extension directives. Optionally include an argument.
6969
Extension(String, Option<String>)
@@ -95,11 +95,6 @@ impl fmt::String for CacheDirective {
9595
}
9696
}
9797

98-
impl fmt::Show for CacheDirective {
99-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
100-
self.to_string().fmt(fmt)
101-
}
102-
}
10398
impl FromStr for CacheDirective {
10499
fn from_str(s: &str) -> Option<CacheDirective> {
105100
use self::CacheDirective::*;

src/header/common/content_length.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use header::shared::util::from_one_raw_str;
77
///
88
/// Simply a wrapper around a `usize`.
99
#[derive(Copy, Clone, PartialEq, Show)]
10-
pub struct ContentLength(pub usize);
10+
pub struct ContentLength(pub u64);
1111

12-
deref!(ContentLength => usize);
12+
deref!(ContentLength => u64);
1313

1414
impl Header for ContentLength {
1515
fn header_name(_: Option<ContentLength>) -> &'static str {
@@ -23,17 +23,7 @@ impl Header for ContentLength {
2323

2424
impl HeaderFormat for ContentLength {
2525
fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
26-
let ContentLength(ref value) = *self;
27-
write!(fmt, "{}", value)
28-
}
29-
}
30-
31-
impl ContentLength {
32-
/// Returns the wrapped length.
33-
#[deprecated = "use Deref instead"]
34-
#[inline]
35-
pub fn len(&self) -> usize {
36-
**self
26+
fmt::String::fmt(&self.0, fmt)
3727
}
3828
}
3929

0 commit comments

Comments
 (0)