Skip to content

Commit 4517ee6

Browse files
committed
Update to rust master
1 parent 7816dca commit 4517ee6

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "curl"
4-
version = "0.1.2"
4+
version = "0.1.3"
55
authors = ["Carl Lerche <me@carllerche.com>"]
66
license = "MIT"
77
repository = "https://github.com/carllerche/curl-rust"

src/http/handle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::hash_map::{HashMap, Occupied, Vacant};
1+
use std::collections::hash_map::{HashMap, Entry};
22

33
use url::Url;
44

@@ -328,12 +328,12 @@ impl<'a, 'b> Request<'a, 'b> {
328328

329329
fn append_header(map: &mut HashMap<String, Vec<String>>, key: &str, val: &str) {
330330
match map.entry(key.to_string()) {
331-
Vacant(entry) => {
331+
Entry::Vacant(entry) => {
332332
let mut values = Vec::new();
333333
values.push(val.to_string());
334334
entry.set(values)
335335
},
336-
Occupied(entry) => entry.into_mut()
336+
Entry::Occupied(entry) => entry.into_mut()
337337
};
338338
}
339339

src/http/header.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ pub fn parse<'a>(buf: &'a [u8]) -> Option<(&'a str, &'a str)> {
9898
}
9999

100100
let name = match str::from_utf8(buf.slice(name_begin, name_end)) {
101-
Some(v) => v,
102-
None => return None
101+
Ok(v) => v,
102+
Err(..) => return None
103103
};
104104

105105
let val = match str::from_utf8(buf.slice(val_begin, val_end)) {
106-
Some(v) => v,
107-
None => return None
106+
Ok(v) => v,
107+
Err(..) => return None
108108
};
109109

110110
Some((name, val))

src/http/response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ impl fmt::Show for Response {
5151
}
5252

5353
match str::from_utf8(self.body.as_slice()) {
54-
Some(b) => try!(write!(fmt, "{}", b)),
55-
None => try!(write!(fmt, "bytes[{}]", self.body.len()))
54+
Ok(b) => try!(write!(fmt, "{}", b)),
55+
Err(..) => try!(write!(fmt, "bytes[{}]", self.body.len()))
5656
}
5757

5858
try!(write!(fmt, "]"));

src/test/server.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::io::net::tcp::{TcpListener,TcpStream};
44
use std::io::timer;
55
use std::io::{Acceptor, Listener};
66
use std::str;
7+
use std::thread::Thread;
78
use std::time::Duration;
89

910
use self::Op::{SendBytes, ReceiveBytes, Wait, Shutdown};
@@ -131,7 +132,7 @@ impl OpSequence {
131132
fn insert_port(bytes: &'static [u8], port: uint) -> Vec<u8> {
132133
let s = str::from_utf8(bytes).unwrap();
133134
let p = port.to_string();
134-
str::replace(s, "{PORT}", p.as_slice()).into_bytes()
135+
s.replace("{PORT}", p.as_slice()).into_bytes()
135136
}
136137

137138
fn parse_request<'a>(req: &'a [u8]) -> (&'a [u8],
@@ -222,17 +223,12 @@ impl OpSequenceResult {
222223

223224
fn start_server() -> Handle {
224225
let (ops_tx, ops_rx) = channel();
225-
let (ini_tx, ini_rx) = channel();
226226

227227
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
228228
let port = listener.socket_name().unwrap().port;
229+
let mut srv = listener.listen().unwrap();
229230

230-
spawn(move|| {
231-
let listener = listener;
232-
let mut srv = listener.listen().unwrap();
233-
234-
ini_tx.send(true);
235-
231+
Thread::spawn(move || {
236232
loop {
237233
let (ops, resp_tx): (OpSequence, Sender<Result<(),String>>) = ops_rx.recv();
238234

@@ -253,10 +249,7 @@ fn start_server() -> Handle {
253249

254250
resp_tx.send(ops.apply(&mut sock, port as uint));
255251
}
256-
});
257-
258-
// Wait until the server is listening
259-
ini_rx.recv();
252+
}).detach();
260253

261254
Handle::new(ops_tx, port)
262255
}

0 commit comments

Comments
 (0)