diff --git a/app/storyteller_web/src/http_server/middleware/ip_filter_middleware.rs b/app/storyteller_web/src/http_server/middleware/ip_filter_middleware.rs index b78c91ffba..015e6b8d14 100644 --- a/app/storyteller_web/src/http_server/middleware/ip_filter_middleware.rs +++ b/app/storyteller_web/src/http_server/middleware/ip_filter_middleware.rs @@ -22,9 +22,50 @@ use std::task::{Context, Poll}; use actix_web::dev::{Service, Transform}; use actix_web::dev::{ServiceRequest, ServiceResponse}; -use actix_web::Error; +use actix_web::{Error, HttpResponse}; use futures_util::future::{err, ok, Either, Ready}; +use derive_more::{Display, Error as ErrorE}; +use actix_web::{ResponseError, HttpMessage, HttpRequest, HttpResponseBuilder}; +use actix_http::StatusCode; +use actix_http::{error, body::Body, Response}; +use actix_web::web::{BytesMut, Buf, BufMut}; +use actix_http::http::{header, HeaderMap, HeaderValue}; +use std::io::Write; + +#[derive(Debug, Display, ErrorE)] +pub struct BannedError { +} + +impl ResponseError for BannedError { + fn status_code(&self) -> StatusCode { + StatusCode::UNAUTHORIZED + } + fn error_response(&self) -> HttpResponse
{ + // let mut res = Response::new(self.status_code()); + // res.headers_mut().insert( + // header::CONTENT_TYPE, + // header::HeaderValue::from_static("application/json"), + // ); + // res.set_body(Body::from(self.to_string())).into() + /*let mut res = Response::new(self.status_code()); + let mut buf = BytesMut::new().writer(); + let _ = write!(buf, "{}", self); + + res.headers_mut().insert( + header::CONTENT_TYPE, + header::HeaderValue::from_static("application/json"), + ); + res.set_body(Body::from(buf.into_inner())).into()*/ + + HttpResponseBuilder::new(self.status_code()) + .set_header(header::CONTENT_TYPE, "application/json") + .body("TODO") + } +} + + + // There are two steps in middleware processing. // 1. Middleware initialization, middleware factory gets called with // next service in chain as parameter. @@ -88,6 +129,15 @@ impl