use std::marker::PhantomData; use actix_net::codec::Framed; use actix_net::service::{NewService, Service}; use futures::future::{ok, FutureResult}; use futures::{Async, IntoFuture, Poll}; use h1::Codec; use request::Request; use super::{verify_handshake, HandshakeError}; pub struct VerifyWebSockets { _t: PhantomData, } impl Default for VerifyWebSockets { fn default() -> Self { VerifyWebSockets { _t: PhantomData } } } impl NewService for VerifyWebSockets { type Request = (Request, Framed); type Response = (Request, Framed); type Error = (HandshakeError, Framed); type InitError = (); type Service = VerifyWebSockets; type Future = FutureResult; fn new_service(&self) -> Self::Future { ok(VerifyWebSockets { _t: PhantomData }) } } impl Service for VerifyWebSockets { type Request = (Request, Framed); type Response = (Request, Framed); type Error = (HandshakeError, Framed); type Future = FutureResult; fn poll_ready(&mut self) -> Poll<(), Self::Error> { Ok(Async::Ready(())) } fn call(&mut self, (req, framed): Self::Request) -> Self::Future { match verify_handshake(&req) { Err(e) => Err((e, framed)).into_future(), Ok(_) => Ok((req, framed)).into_future(), } } }