From 904ebf34a5054f5234c7914fc38a253de99b187d Mon Sep 17 00:00:00 2001 From: asonix Date: Mon, 20 Apr 2020 12:31:22 -0500 Subject: [PATCH] Guard CreateCommunity, represent impossible error with Infallible --- server/src/routes/api.rs | 7 ++++++- server/src/routes/websocket.rs | 2 +- server/src/websocket/server.rs | 5 +++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/server/src/routes/api.rs b/server/src/routes/api.rs index 025c6e0a..629bd49d 100644 --- a/server/src/routes/api.rs +++ b/server/src/routes/api.rs @@ -40,10 +40,15 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) { .route(web::get().to(route_get::)), ) // Community + .service( + web::resource("/community") + .guard(guard::Post()) + .wrap(rate_limit.post()) + .route(web::post().to(route_post::)), + ) .service( web::scope("/community") .wrap(rate_limit.message()) - .route("", web::post().to(route_post::)) .route("", web::get().to(route_get::)) .route("", web::put().to(route_post::)) .route("/list", web::get().to(route_get::)) diff --git a/server/src/routes/websocket.rs b/server/src/routes/websocket.rs index eb157590..e1efdc0f 100644 --- a/server/src/routes/websocket.rs +++ b/server/src/routes/websocket.rs @@ -120,7 +120,7 @@ impl StreamHandler> for WSSession { .then(|res, _, ctx| { match res { Ok(Ok(res)) => ctx.text(res), - Ok(Err(e)) => error!("{}", e), + Ok(Err(e)) => match e {}, Err(e) => error!("{}", &e), } actix::fut::ready(()) diff --git a/server/src/websocket/server.rs b/server/src/websocket/server.rs index d16ecf85..cd78bbc7 100644 --- a/server/src/websocket/server.rs +++ b/server/src/websocket/server.rs @@ -38,7 +38,7 @@ pub struct Disconnect { /// The messages sent to websocket clients #[derive(Serialize, Deserialize, Message)] -#[rtype(result = "Result")] +#[rtype(result = "Result")] pub struct StandardMessage { /// Id of the client session pub id: ConnectionId, @@ -905,6 +905,7 @@ where match op2 { UserOperation::Register => rate_limiter.register().wrap(ip, fut).await, UserOperation::CreatePost => rate_limiter.post().wrap(ip, fut).await, + UserOperation::CreateCommunity => rate_limiter.post().wrap(ip, fut).await, _ => rate_limiter.message().wrap(ip, fut).await, } } @@ -963,7 +964,7 @@ impl Handler for ChatServer { /// Handler for Message message. impl Handler for ChatServer { - type Result = ResponseFuture>; + type Result = ResponseFuture>; fn handle(&mut self, msg: StandardMessage, ctx: &mut Context) -> Self::Result { let fut = self.parse_json_message(msg, ctx);