kegani-cli 0.1.1

CLI tool for Kegani framework
Documentation
//! Auth middleware

use actix_web::{dev::{ServiceRequest, ServiceResponse, Transform}, Error};
use std::future::{Ready, Future};
use std::pin::Pin;

pub struct AuthMiddleware;

impl<S, B> Transform<S, ServiceRequest> for AuthMiddleware
where S: actix_service::Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error>, S::Future: 'static, B: 'static {
type Response = ServiceResponse<BoxBody>;
type Error = Error;
type Transform = AuthMiddlewareService<S>;
type InitError = ();
type Future = Ready<Result<Self::Transform, Self::InitError>>;

fn new_transform(&self, service: S) -> Self::Future {
ready(Ok(AuthMiddlewareService { service }))
}
}

pub struct AuthMiddlewareService<S> { service: S }

impl<S, B> actix_service::Service<ServiceRequest> for AuthMiddlewareService<S>
where S: actix_service::Service<ServiceRequest, Response = ServiceResponse<B>, Error = Error> {
type Response = ServiceResponse<BoxBody>;
type Error = Error;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;

fn poll_ready(&self, cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
self.service.poll_ready(cx)
}

fn call(&self, req: ServiceRequest) -> Self::Future {
Box::pin(self.service.call(req))
}
}