Skip to content

Commit

Permalink
webdriver: Merge pull request #6 from jdm/servo
Browse files Browse the repository at this point in the history
Update to compile with rustc d3c49d2140fc65e8bb7d7cf25bfe74dda6ce5ecf/ru...

Source-Repo: https://github.com/mozilla/webdriver-rust
Source-Revision: 906806d51783b5caad89432bf8ce008f2f4968fc

--HG--
extra : subtree_source : http%3A//tristan.corp.lon2.mozilla.com%3A8000
extra : subtree_revision : a1ed74dee3765821147fec6cf622094c15d31e4f
  • Loading branch information
jdm committed Apr 3, 2015
1 parent 0d61b12 commit 48aa06b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
11 changes: 4 additions & 7 deletions testing/webdriver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ authors = ["James Graham <james@hoppipolla.co.uk>"]

[dependencies]
log = "0.2.4"
regex = "0.1.15"
rustc-serialize = "0.2.15"
uuid = "0.1.10"

[dependencies.hyper]
git = "https://github.com/hyperium/hyper"
branch = "master"
regex = "0.1.18"
rustc-serialize = "0.3.4"
uuid = "0.1.11"
hyper = "0.3"
3 changes: 2 additions & 1 deletion testing/webdriver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(old_io)]
#![feature(io)]
#![feature(net)]
#![feature(core)]
#![feature(collections)]
#![allow(non_snake_case)]
Expand Down
27 changes: 14 additions & 13 deletions testing/webdriver/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::old_io::net::ip::IpAddr;
use std::net::IpAddr;
use std::num::FromPrimitive;
use std::io::{Write, Read};
use std::sync::Mutex;
use std::sync::mpsc::{channel, Receiver, Sender};
use std::thread;
Expand Down Expand Up @@ -153,10 +154,10 @@ impl Handler for HttpHandler {
let mut req = req;
let mut res = res;

let body = match req.method {
Method::Post => req.read_to_string().unwrap(),
_ => "".to_string()
};
let mut body = String::new();
if let Method::Post = req.method {
req.read_to_string(&mut body).unwrap();
}
debug!("Got request {} {:?}", req.method, req.uri);
match req.uri {
AbsolutePath(path) => {
Expand Down Expand Up @@ -214,25 +215,25 @@ impl Handler for HttpHandler {
*status_code = FromPrimitive::from_u32(status).unwrap();
}
res.headers_mut().set(ContentLength(resp_body.len() as u64));
let mut stream = res.start();
stream.write_str(&resp_body[..]).unwrap();
stream.unwrap().end().unwrap();
let mut stream = res.start().unwrap();
stream.write_all(&resp_body.as_bytes()).unwrap();
stream.end().unwrap();
},
_ => {}
}
}
}

pub fn start<T: 'static+WebDriverHandler>(ip_address: IpAddr, port: u16, handler: T) {
let server = Server::http(ip_address, port);

let (msg_send, msg_recv) = channel();

let api = WebDriverHttpApi::new();
let http_handler = HttpHandler::new(api, msg_send);
let server = Server::http(http_handler);

thread::spawn(move || {
let mut dispatcher = Dispatcher::new(handler);
dispatcher.run(msg_recv)
});
let api = WebDriverHttpApi::new();
let http_handler = HttpHandler::new(api, msg_send.clone());
server.listen(http_handler).unwrap();
server.listen(ip_address, port).unwrap();
}

0 comments on commit 48aa06b

Please sign in to comment.