pub struct PyMiddlewares { /* private fields */ }
Expand description
Structure holding the list of Python middlewares that will be executed by this server.
Middlewares are executed one after each other inside the crate::PyMiddlewareLayer Tower layer.
Implementations
sourceimpl PyMiddlewares
impl PyMiddlewares
sourcepub fn new<P>(handlers: Vec<PyMiddlewareHandler>) -> Selfwhere
PyMiddlewareException: IntoResponse<P>,
pub fn new<P>(handlers: Vec<PyMiddlewareHandler>) -> Selfwhere
PyMiddlewareException: IntoResponse<P>,
Create a new instance of PyMiddlewareHandlers
from a list of heandlers.
sourcepub fn run(
&mut self,
request: Request<Body>,
locals: TaskLocals
) -> BoxFuture<'static, Result<Request<Body>, Response<BoxBody>>>
pub fn run(
&mut self,
request: Request<Body>,
locals: TaskLocals
) -> BoxFuture<'static, Result<Request<Body>, Response<BoxBody>>>
Execute all the available Python middlewares in order of registration.
Once the response is returned by the Python interpreter, different scenarios can happen:
- Middleware not returning will let the execution continue to the next middleware without changing the original request.
- Middleware returning a modified PyRequest will update the original request before continuing the execution of the next middleware.
- Middleware returning a PyResponse will immediately terminate the request handling and return the response constructed from Python.
- Middleware raising PyMiddlewareException will immediately terminate the request handling and return a protocol specific error, with the option of setting the HTTP return code.
- Middleware raising any other exception will immediately terminate the request handling and return a protocol specific error, with HTTP status code 500.
Trait Implementations
sourceimpl Clone for PyMiddlewares
impl Clone for PyMiddlewares
sourcefn clone(&self) -> PyMiddlewares
fn clone(&self) -> PyMiddlewares
Returns a copy of the value. Read more
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations
impl !RefUnwindSafe for PyMiddlewares
impl Send for PyMiddlewares
impl Sync for PyMiddlewares
impl Unpin for PyMiddlewares
impl UnwindSafe for PyMiddlewares
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more