From f35a3ea6dbd0d9f8d24324c14ea1eaf0eee29f2d Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 30 Oct 2017 20:39:56 -0700 Subject: [PATCH] prepare release --- CHANGES.md | 2 +- Cargo.toml | 4 ++-- README.md | 11 +++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f83e7b5bd..3217f081e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,7 +1,7 @@ # CHANGES -## 0.2.0 (2017-10-xx) +## 0.2.0 (2017-10-30) * Do not use `http::Uri` as it can not parse some valid paths diff --git a/Cargo.toml b/Cargo.toml index 9d29f7a3b..72fbfdd1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,9 +50,9 @@ tokio-core = "0.1" # h2 = { git = 'https://github.com/carllerche/h2', optional = true } [dependencies.actix] -#version = ">=0.3.1" +version = ">=0.3.1" #path = "../actix" -git = "https://github.com/actix/actix.git" +#git = "https://github.com/actix/actix.git" default-features = false features = [] diff --git a/README.md b/README.md index 5696f75de..7424cfc69 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ To use `actix-web`, add this to your `Cargo.toml`: ```toml [dependencies] -actix-web = "0.1" +actix-web = "0.2" ``` ## Example @@ -51,23 +51,29 @@ use actix_web::*; struct MyWebSocket; +/// Actor with http context impl Actor for MyWebSocket { type Context = HttpContext; } +/// Http route handler impl Route for MyWebSocket { type State = (); fn request(req: &mut HttpRequest, payload: Payload, ctx: &mut HttpContext) -> RouteResult { + // websocket handshake let resp = ws::handshake(req)?; + // send HttpResponse back to peer ctx.start(resp); + // convert bytes stream to a stream of `ws::Message` and handle stream ctx.add_stream(ws::WsStream::new(payload)); Reply::async(MyWebSocket) } } +/// Standard actix's stream handler for a stream of `ws::Message` impl StreamHandler for MyWebSocket { fn started(&mut self, ctx: &mut Self::Context) { println!("WebSocket session openned"); @@ -82,9 +88,10 @@ impl Handler for MyWebSocket { fn handle(&mut self, msg: ws::Message, ctx: &mut HttpContext) -> Response { + // process websocket messages println!("WS: {:?}", msg); match msg { - ws::Message::Ping(msg) => ws::WsWriter::pong(ctx, msg), + ws::Message::Ping(msg) => ws::WsWriter::pong(ctx, &msg), ws::Message::Text(text) => ws::WsWriter::text(ctx, &text), ws::Message::Binary(bin) => ws::WsWriter::binary(ctx, bin), ws::Message::Closed | ws::Message::Error => {