Updated to latest hyper with patched mio

This commit is contained in:
arkpar 2016-06-27 10:39:37 +02:00
parent 4f1f33d1b8
commit c21550a663
7 changed files with 36 additions and 31 deletions

24
Cargo.lock generated
View File

@ -278,7 +278,7 @@ dependencies = [
"clippy 0.0.77 (registry+https://github.com/rust-lang/crates.io-index)", "clippy 0.0.77 (registry+https://github.com/rust-lang/crates.io-index)",
"ethcore-rpc 1.3.0", "ethcore-rpc 1.3.0",
"ethcore-util 1.3.0", "ethcore-util 1.3.0",
"hyper 0.9.3 (git+https://github.com/ethcore/hyper)", "hyper 0.9.4 (git+https://github.com/ethcore/hyper)",
"jsonrpc-core 2.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 2.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)", "jsonrpc-http-server 5.1.0 (git+https://github.com/ethcore/jsonrpc-http-server.git)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@ -546,16 +546,15 @@ dependencies = [
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.9.3" version = "0.9.4"
source = "git+https://github.com/ethcore/hyper#dbb4cf160ebf242f7f0459d547c40e9e6877ccf4" source = "git+https://github.com/ethcore/hyper#7ccfcb2aa7e6aa6300efa8cebd6a0e6ce55582ea"
dependencies = [ dependencies = [
"cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "cookie 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rotor 0.6.3 (git+https://github.com/ethcore/rotor)",
"rotor 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"spmc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "spmc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
@ -630,9 +629,9 @@ dependencies = [
[[package]] [[package]]
name = "jsonrpc-http-server" name = "jsonrpc-http-server"
version = "5.1.0" version = "5.1.0"
source = "git+https://github.com/ethcore/jsonrpc-http-server.git#0c99d308bc15e8fae50642eff77a3e1fd7610652" source = "git+https://github.com/ethcore/jsonrpc-http-server.git#e59c2fbaca499620874023755cb91f05b858ffe7"
dependencies = [ dependencies = [
"hyper 0.9.3 (git+https://github.com/ethcore/hyper)", "hyper 0.9.4 (git+https://github.com/ethcore/hyper)",
"jsonrpc-core 2.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 2.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -731,7 +730,7 @@ dependencies = [
[[package]] [[package]]
name = "mio" name = "mio"
version = "0.5.1" version = "0.5.1"
source = "git+https://github.com/ethcore/mio?branch=v0.5.x#1fc881771fb8c2517317b4f805d7b88235be422b" source = "git+https://github.com/ethcore/mio?branch=v0.5.x#3842d3b250ffd7bd9b16f9586b875ddcbac2b0dd"
dependencies = [ dependencies = [
"bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1057,7 +1056,7 @@ dependencies = [
[[package]] [[package]]
name = "quick-error" name = "quick-error"
version = "0.2.2" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
@ -1121,12 +1120,11 @@ dependencies = [
[[package]] [[package]]
name = "rotor" name = "rotor"
version = "0.6.3" version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/ethcore/rotor#e63d45137b2eb66d1e085a7c6321a5db8b187576"
dependencies = [ dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.5.1 (git+https://github.com/ethcore/mio?branch=v0.5.x)",
"quick-error 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]

View File

@ -42,11 +42,11 @@ pub struct EndpointInfo {
pub trait Endpoint : Send + Sync { pub trait Endpoint : Send + Sync {
fn info(&self) -> Option<&EndpointInfo> { None } fn info(&self) -> Option<&EndpointInfo> { None }
fn to_handler(&self, path: EndpointPath) -> Box<server::Handler<HttpStream>>; fn to_handler(&self, path: EndpointPath) -> Box<server::Handler<HttpStream> + Send>;
} }
pub type Endpoints = BTreeMap<String, Box<Endpoint>>; pub type Endpoints = BTreeMap<String, Box<Endpoint>>;
pub type Handler = server::Handler<HttpStream>; pub type Handler = server::Handler<HttpStream> + Send;
pub struct ContentHandler { pub struct ContentHandler {
content: String, content: String,
@ -65,7 +65,7 @@ impl ContentHandler {
} }
impl server::Handler<HttpStream> for ContentHandler { impl server::Handler<HttpStream> for ContentHandler {
fn on_request(&mut self, _request: server::Request) -> Next { fn on_request(&mut self, _request: server::Request<HttpStream>) -> Next {
Next::write() Next::write()
} }

View File

@ -132,9 +132,16 @@ impl Server {
special.clone(), special.clone(),
authorization.clone(), authorization.clone(),
)) ))
.map(|l| Server { .map(|(l, srv)| {
::std::thread::spawn(move || {
srv.run();
});
Server {
server: Some(l), server: Some(l),
panic_handler: panic_handler, panic_handler: panic_handler,
}
}) })
.map_err(ServerError::from) .map_err(ServerError::from)
} }

View File

@ -86,7 +86,7 @@ impl<T: Dapp> PageHandler<T> {
} }
impl<T: Dapp> server::Handler<HttpStream> for PageHandler<T> { impl<T: Dapp> server::Handler<HttpStream> for PageHandler<T> {
fn on_request(&mut self, req: server::Request) -> Next { fn on_request(&mut self, req: server::Request<HttpStream>) -> Next {
self.file = match *req.uri() { self.file = match *req.uri() {
RequestUri::AbsolutePath(ref path) => { RequestUri::AbsolutePath(ref path) => {
self.app.file(&self.extract_path(path)) self.app.file(&self.extract_path(path))

View File

@ -27,13 +27,13 @@ pub enum Authorized {
/// Authorization was successful. /// Authorization was successful.
Yes, Yes,
/// Unsuccessful authorization. Handler for further work is returned. /// Unsuccessful authorization. Handler for further work is returned.
No(Box<server::Handler<HttpStream>>), No(Box<server::Handler<HttpStream> + Send>),
} }
/// Authorization interface /// Authorization interface
pub trait Authorization : Send + Sync { pub trait Authorization : Send + Sync {
/// Checks if authorization is valid. /// Checks if authorization is valid.
fn is_authorized(&self, req: &server::Request)-> Authorized; fn is_authorized(&self, req: &server::Request<HttpStream>)-> Authorized;
} }
/// HTTP Basic Authorization handler /// HTTP Basic Authorization handler
@ -45,13 +45,13 @@ pub struct HttpBasicAuth {
pub struct NoAuth; pub struct NoAuth;
impl Authorization for NoAuth { impl Authorization for NoAuth {
fn is_authorized(&self, _req: &server::Request)-> Authorized { fn is_authorized(&self, _req: &server::Request<HttpStream>)-> Authorized {
Authorized::Yes Authorized::Yes
} }
} }
impl Authorization for HttpBasicAuth { impl Authorization for HttpBasicAuth {
fn is_authorized(&self, req: &server::Request) -> Authorized { fn is_authorized(&self, req: &server::Request<HttpStream>) -> Authorized {
let auth = self.check_auth(&req); let auth = self.check_auth(&req);
match auth { match auth {
@ -89,7 +89,7 @@ impl HttpBasicAuth {
self.users.get(&username.to_owned()).map_or(false, |pass| pass == password) self.users.get(&username.to_owned()).map_or(false, |pass| pass == password)
} }
fn check_auth(&self, req: &server::Request) -> Access { fn check_auth(&self, req: &server::Request<HttpStream>) -> Access {
match req.headers().get::<header::Authorization<header::Basic>>() { match req.headers().get::<header::Authorization<header::Basic>>() {
Some(&header::Authorization( Some(&header::Authorization(
header::Basic { ref username, password: Some(ref password) } header::Basic { ref username, password: Some(ref password) }
@ -105,7 +105,7 @@ pub struct UnauthorizedHandler {
} }
impl server::Handler<HttpStream> for UnauthorizedHandler { impl server::Handler<HttpStream> for UnauthorizedHandler {
fn on_request(&mut self, _request: server::Request) -> Next { fn on_request(&mut self, _request: server::Request<HttpStream>) -> Next {
Next::write() Next::write()
} }
@ -141,7 +141,7 @@ impl server::Handler<HttpStream> for UnauthorizedHandler {
pub struct AuthRequiredHandler; pub struct AuthRequiredHandler;
impl server::Handler<HttpStream> for AuthRequiredHandler { impl server::Handler<HttpStream> for AuthRequiredHandler {
fn on_request(&mut self, _request: server::Request) -> Next { fn on_request(&mut self, _request: server::Request<HttpStream>) -> Next {
Next::write() Next::write()
} }

View File

@ -49,12 +49,12 @@ pub struct Router<A: Authorization + 'static> {
endpoints: Arc<Endpoints>, endpoints: Arc<Endpoints>,
special: Arc<HashMap<SpecialEndpoint, Box<Endpoint>>>, special: Arc<HashMap<SpecialEndpoint, Box<Endpoint>>>,
authorization: Arc<A>, authorization: Arc<A>,
handler: Box<server::Handler<HttpStream>>, handler: Box<server::Handler<HttpStream> + Send>,
} }
impl<A: Authorization + 'static> server::Handler<HttpStream> for Router<A> { impl<A: Authorization + 'static> server::Handler<HttpStream> for Router<A> {
fn on_request(&mut self, req: server::Request) -> Next { fn on_request(&mut self, req: server::Request<HttpStream>) -> Next {
// Check authorization // Check authorization
let auth = self.authorization.is_authorized(&req); let auth = self.authorization.is_authorized(&req);
@ -124,7 +124,7 @@ impl<A: Authorization> Router<A> {
} }
} }
fn extract_url(req: &server::Request) -> Option<Url> { fn extract_url(req: &server::Request<HttpStream>) -> Option<Url> {
match *req.uri() { match *req.uri() {
uri::RequestUri::AbsoluteUri(ref url) => { uri::RequestUri::AbsoluteUri(ref url) => {
match Url::from_generic_url(url.clone()) { match Url::from_generic_url(url.clone()) {

View File

@ -33,7 +33,7 @@ impl Redirection {
} }
impl server::Handler<HttpStream> for Redirection { impl server::Handler<HttpStream> for Redirection {
fn on_request(&mut self, _request: server::Request) -> Next { fn on_request(&mut self, _request: server::Request<HttpStream>) -> Next {
Next::write() Next::write()
} }