Minimal System UI

This commit is contained in:
Tomasz Drwięga
2016-05-31 20:12:47 +02:00
parent 70cecb49b0
commit 4d29508b4c
5 changed files with 63 additions and 7 deletions

View File

@@ -14,9 +14,10 @@ rustc_version = "0.1"
jsonrpc-core = "2.0"
log = "0.3"
env_logger = "0.3"
ws = "0.4.7"
ws = { git = "https://github.com/ethcore/ws-rs.git" }
ethcore-util = { path = "../util" }
ethcore-rpc = { path = "../rpc" }
parity-minimal-sysui = { path = "../../parity-dapps-minimal-sysui-rs" }
clippy = { version = "0.0.69", optional = true}

View File

@@ -50,6 +50,7 @@ extern crate ethcore_util as util;
extern crate ethcore_rpc as rpc;
extern crate jsonrpc_core;
extern crate ws;
extern crate parity_minimal_sysui as sysui;
mod ws_server;
pub use ws_server::*;

View File

@@ -89,7 +89,7 @@ impl Server {
fn start(addr: SocketAddr, handler: Arc<IoHandler>, queue: Arc<ConfirmationsQueue>) -> Result<Server, ServerError> {
let config = {
let mut config = ws::Settings::default();
config.max_connections = 5;
config.max_connections = 10;
config.method_strict = true;
config
};

View File

@@ -17,6 +17,7 @@
//! Session handlers factory.
use ws;
use sysui;
use std::sync::Arc;
use jsonrpc_core::IoHandler;
@@ -26,6 +27,28 @@ pub struct Session {
}
impl ws::Handler for Session {
fn on_request(&mut self, req: &ws::Request) -> ws::Result<(ws::Response)> {
// Detect if it's a websocket request.
if req.header("sec-websocket-key").is_some() {
return ws::Response::from_request(req);
}
// Otherwise try to serve a page.
sysui::handle(req.resource())
.map(|f| {
let content_len = format!("{}", f.content.as_bytes().len());
let mut res = ws::Response::ok(f.content.into());
{
let mut headers = res.headers_mut();
headers.push(("Server".into(), "Parity/SystemUI".as_bytes().to_vec()));
headers.push(("Connection".into(), "Closed".as_bytes().to_vec()));
headers.push(("Content-Length".into(), content_len.as_bytes().to_vec()));
headers.push(("Content-Type".into(), f.mime.as_bytes().to_vec()));
}
Ok(res)
}).unwrap_or_else(|| ws::Response::from_request(req))
}
fn on_message(&mut self, msg: ws::Message) -> ws::Result<()> {
let req = try!(msg.as_text());
match self.handler.handle_request(req) {