1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-27 17:52:56 +01:00

prepare release

This commit is contained in:
Nikolay Kim 2017-10-30 20:39:56 -07:00
parent 26c13a81d2
commit f35a3ea6db
3 changed files with 12 additions and 5 deletions

View File

@ -1,7 +1,7 @@
# CHANGES # 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 * Do not use `http::Uri` as it can not parse some valid paths

View File

@ -50,9 +50,9 @@ tokio-core = "0.1"
# h2 = { git = 'https://github.com/carllerche/h2', optional = true } # h2 = { git = 'https://github.com/carllerche/h2', optional = true }
[dependencies.actix] [dependencies.actix]
#version = ">=0.3.1" version = ">=0.3.1"
#path = "../actix" #path = "../actix"
git = "https://github.com/actix/actix.git" #git = "https://github.com/actix/actix.git"
default-features = false default-features = false
features = [] features = []

View File

@ -27,7 +27,7 @@ To use `actix-web`, add this to your `Cargo.toml`:
```toml ```toml
[dependencies] [dependencies]
actix-web = "0.1" actix-web = "0.2"
``` ```
## Example ## Example
@ -51,23 +51,29 @@ use actix_web::*;
struct MyWebSocket; struct MyWebSocket;
/// Actor with http context
impl Actor for MyWebSocket { impl Actor for MyWebSocket {
type Context = HttpContext<Self>; type Context = HttpContext<Self>;
} }
/// Http route handler
impl Route for MyWebSocket { impl Route for MyWebSocket {
type State = (); type State = ();
fn request(req: &mut HttpRequest, fn request(req: &mut HttpRequest,
payload: Payload, ctx: &mut HttpContext<Self>) -> RouteResult<Self> payload: Payload, ctx: &mut HttpContext<Self>) -> RouteResult<Self>
{ {
// websocket handshake
let resp = ws::handshake(req)?; let resp = ws::handshake(req)?;
// send HttpResponse back to peer
ctx.start(resp); ctx.start(resp);
// convert bytes stream to a stream of `ws::Message` and handle stream
ctx.add_stream(ws::WsStream::new(payload)); ctx.add_stream(ws::WsStream::new(payload));
Reply::async(MyWebSocket) Reply::async(MyWebSocket)
} }
} }
/// Standard actix's stream handler for a stream of `ws::Message`
impl StreamHandler<ws::Message> for MyWebSocket { impl StreamHandler<ws::Message> for MyWebSocket {
fn started(&mut self, ctx: &mut Self::Context) { fn started(&mut self, ctx: &mut Self::Context) {
println!("WebSocket session openned"); println!("WebSocket session openned");
@ -82,9 +88,10 @@ impl Handler<ws::Message> for MyWebSocket {
fn handle(&mut self, msg: ws::Message, ctx: &mut HttpContext<Self>) fn handle(&mut self, msg: ws::Message, ctx: &mut HttpContext<Self>)
-> Response<Self, ws::Message> -> Response<Self, ws::Message>
{ {
// process websocket messages
println!("WS: {:?}", msg); println!("WS: {:?}", msg);
match 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::Text(text) => ws::WsWriter::text(ctx, &text),
ws::Message::Binary(bin) => ws::WsWriter::binary(ctx, bin), ws::Message::Binary(bin) => ws::WsWriter::binary(ctx, bin),
ws::Message::Closed | ws::Message::Error => { ws::Message::Closed | ws::Message::Error => {