Closed asonix closed 5 years ago
Lucky us, it is still in alpha, so we a free to make any changes if required.
Can you provide an example of the code you are trying to make? I had never used extensions in actix-web
and I'm not sure why mutable reference to ServiceRequest
is not enough in that case.
Here's the contents of the closure that I'm passing to the middleware:
if let Some(data) = request.app_data::<SledEndpoint>() {
let bearer = bearer.clone();
let scopes = scopes.clone();
let f = actix_threadpool::run(move || {
let bearer = bearer.clone();
let mut resource = data.resource(scopes.clone());
protect(&mut resource, &WrappedResource(&bearer)).map_err(|_| AccessError)
})
.map(move |grant| {
// I move the request into the future here
request.extensions_mut().insert(Grant(grant));
request
})
.map_err(|_| AccessError.into());
Box::new(f)
} else {
Box::new(err(AccessError.into()))
}
Ah, the futures 0.1 limitations, got it.
I've made the owned-middleware
branch (#9 also), you can check it out. I'll merge and publish it after your test results.
Somehow I've forgot about merging it, sorry about that. Same to #7 I'm closing this issue, because changes from the linked and this one issues were merged and published as a 0.3.0 version.
Hello!
I'm trying to use the middleware you've provided in a crate to implement OAuth2, and I've come to the realization I need access to the
ServiceRequest
in myvalidator_fn
in order to set an extension. SinceServiceRequest
is only borrowed, I can't move it into the future returned by thevalidator_fn
.You could enable this just by making
validator_fn
own theServiceRequest
and requiring that it return anIntoFuture<Item = ServiceRequest, ...>