Hi @zenith gulch, thank you for your help in the past few days. I ended up writing two middlewares, and request extensions work when used in the handler.
I'm trying to add the extension in one middleware and pass it to the other one. But in the macro of the handler on wrap = "from_fn(verify_proof_of_purchase)" , I get the following error and my first idea is that I need to specify in from_fn<...> that the second middleware accepts an extension.
the trait bound `MiddlewareFn<fn(ServiceRequest, actix_web_lab::middleware::Next<_>, std::option::Option<ReqData<ProofOfPurchaseRequest>>) -> impl futures_util::Future<Output = Result<ServiceResponse<impl MessageBody>, actix_web::Error>> {verify_proof_of_purchase::<_>}, _>: Transform<actix_web::resource::ResourceService, ServiceRequest>` is not satisfied the following other types implement trait `Transform<S, Req>`: MiddlewareFn<F, ()> MiddlewareFn<F, (E1,)> MiddlewareFn<F, (E1, E2)> MiddlewareFn<F, (E1, E2, E3)> MiddlewareFn<F, (E1, E2, E3, E4)> MiddlewareFn<F, (E1, E2, E3, E4, E5)> MiddlewareFn<F, (E1, E2, E3, E4, E5, E6)> MiddlewareFn<F, (E1, E2, E3, E4, E5, E6, E7)> and 2 others
Here the code two middlewares and the handler
pub async fn verify_presentation_jwt(
req: ServiceRequest,
next: Next<impl MessageBody>,
) -> Result<ServiceResponse<impl MessageBody>, Error> {
req.extensions_mut().insert( ProofOfPurchaseRequest { ... });
}
pub async fn verify_proof_of_purchase(
req: ServiceRequest,
next: Next<impl MessageBody>,
msg: Option<ReqData<ProofOfPurchaseRequest>>,
) -> Result<ServiceResponse<impl MessageBody>, Error> { ... }
#[get("/assets/download",
wrap = "from_fn(verify_proof_of_purchase)",
wrap = "from_fn(verify_presentation_jwt)")]
async fn download_asset(
req: HttpRequest,
query_params: web::Query<QueryAssetAlias>,
db_pool: web::Data<Pool>,
) -> ... { ... } ```