mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-23 16:21:06 +01:00
prepare release
This commit is contained in:
parent
26c13a81d2
commit
f35a3ea6db
@ -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
|
||||
|
||||
|
@ -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 = []
|
||||
|
||||
|
11
README.md
11
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<Self>;
|
||||
}
|
||||
|
||||
/// Http route handler
|
||||
impl Route for MyWebSocket {
|
||||
type State = ();
|
||||
|
||||
fn request(req: &mut HttpRequest,
|
||||
payload: Payload, ctx: &mut HttpContext<Self>) -> RouteResult<Self>
|
||||
{
|
||||
// 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<ws::Message> for MyWebSocket {
|
||||
fn started(&mut self, ctx: &mut Self::Context) {
|
||||
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>)
|
||||
-> Response<Self, ws::Message>
|
||||
{
|
||||
// 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 => {
|
||||
|
Loading…
Reference in New Issue
Block a user