1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 02:19:22 +02:00

simplify Frame::Message; impl Try for Reply

This commit is contained in:
Nikolay Kim
2017-10-13 14:43:17 -07:00
parent c0e73c7275
commit 0447c66de1
13 changed files with 226 additions and 141 deletions

View File

@ -1,3 +1,4 @@
#![feature(try_trait)]
#![allow(dead_code, unused_variables)]
extern crate actix;
extern crate actix_http;
@ -24,7 +25,7 @@ impl Route for MyRoute {
ctx.add_stream(payload);
Reply::stream(MyRoute{req: Some(req)})
} else {
Reply::reply(req, httpcodes::HTTPOk)
Reply::reply(httpcodes::HTTPOk)
}
}
}
@ -42,7 +43,7 @@ impl Handler<PayloadItem> for MyRoute {
{
println!("CHUNK: {:?}", msg);
if let Some(req) = self.req.take() {
ctx.start(req, httpcodes::HTTPOk);
ctx.start(httpcodes::HTTPOk);
ctx.write_eof();
}
Self::empty()
@ -58,16 +59,12 @@ impl Actor for MyWS {
impl Route for MyWS {
type State = ();
fn request(req: HttpRequest, payload: Payload, ctx: &mut HttpContext<Self>) -> Reply<Self> {
match ws::handshake(&req) {
Ok(resp) => {
ctx.start(req, resp);
ctx.add_stream(ws::WsStream::new(payload));
Reply::stream(MyWS{})
},
Err(err) =>
Reply::reply(req, err)
}
fn request(req: HttpRequest, payload: Payload, ctx: &mut HttpContext<Self>) -> Reply<Self>
{
let resp = ws::handshake(&req)?;
ctx.start(resp);
ctx.add_stream(ws::WsStream::new(payload));
Reply::stream(MyWS{})
}
}