Creating a logging middleware
Previously we have implemented the FromRequest trait for our JWT. The FromRequest trait enabled us to extract the token from the header and pass the extracted ID from the token into the view. However, we must pass the JWT struct into the view for this process to work. For our purpose, we need our logger to automatically work on every request, and we want the logger to also log the response code. First, we create an Actix logger struct implement the Transform trait. The Transform trait is essentially the interface of a service factory. A service is an async function that converts a Request to a Response. For our middleware, we initially need to import the following code:
// glue/src/network_wrappers/actix_web.rs
use actix_web::{dev::ServiceRequest, dev::ServiceResponse, Error};
use actix_web::dev::{Transform, Service};
use futures_util::future::{ok, Ready};
use std::task::{Context, Poll};
use std::pin::Pin;
We can then implement the Transform trait for a...