2018-10-22 18:59:20 +02:00
|
|
|
use std::marker::PhantomData;
|
|
|
|
|
2018-12-11 03:08:33 +01:00
|
|
|
use actix_codec::Framed;
|
|
|
|
use actix_service::{NewService, Service};
|
2018-10-22 18:59:20 +02:00
|
|
|
use futures::future::{ok, FutureResult};
|
|
|
|
use futures::{Async, IntoFuture, Poll};
|
|
|
|
|
2018-12-06 23:32:52 +01:00
|
|
|
use crate::h1::Codec;
|
|
|
|
use crate::request::Request;
|
2018-10-22 18:59:20 +02:00
|
|
|
|
|
|
|
use super::{verify_handshake, HandshakeError};
|
|
|
|
|
|
|
|
pub struct VerifyWebSockets<T> {
|
|
|
|
_t: PhantomData<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Default for VerifyWebSockets<T> {
|
|
|
|
fn default() -> Self {
|
|
|
|
VerifyWebSockets { _t: PhantomData }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-09 16:37:23 +01:00
|
|
|
impl<T> NewService for VerifyWebSockets<T> {
|
|
|
|
type Request = (Request, Framed<T, Codec>);
|
2018-10-22 18:59:20 +02:00
|
|
|
type Response = (Request, Framed<T, Codec>);
|
|
|
|
type Error = (HandshakeError, Framed<T, Codec>);
|
|
|
|
type InitError = ();
|
|
|
|
type Service = VerifyWebSockets<T>;
|
|
|
|
type Future = FutureResult<Self::Service, Self::InitError>;
|
|
|
|
|
2019-02-22 23:21:35 +01:00
|
|
|
fn new_service(&self, _: &()) -> Self::Future {
|
2018-10-22 18:59:20 +02:00
|
|
|
ok(VerifyWebSockets { _t: PhantomData })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-09 16:37:23 +01:00
|
|
|
impl<T> Service for VerifyWebSockets<T> {
|
|
|
|
type Request = (Request, Framed<T, Codec>);
|
2018-10-22 18:59:20 +02:00
|
|
|
type Response = (Request, Framed<T, Codec>);
|
|
|
|
type Error = (HandshakeError, Framed<T, Codec>);
|
|
|
|
type Future = FutureResult<Self::Response, Self::Error>;
|
|
|
|
|
|
|
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
|
|
|
Ok(Async::Ready(()))
|
|
|
|
}
|
|
|
|
|
2018-11-30 20:57:57 +01:00
|
|
|
fn call(&mut self, (req, framed): (Request, Framed<T, Codec>)) -> Self::Future {
|
2018-10-22 18:59:20 +02:00
|
|
|
match verify_handshake(&req) {
|
|
|
|
Err(e) => Err((e, framed)).into_future(),
|
|
|
|
Ok(_) => Ok((req, framed)).into_future(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|