actix / actix-extras

@@ -1,8 +1,6 @@
Loading
1 1
//! Cookie based sessions. See docs for [`CookieSession`].
2 2
3 -
use std::collections::HashMap;
4 -
use std::rc::Rc;
5 -
use std::task::{Context, Poll};
3 +
use std::{collections::HashMap, rc::Rc};
6 4
7 5
use actix_service::{Service, Transform};
8 6
use actix_web::cookie::{Cookie, CookieJar, Key, SameSite};
@@ -326,9 +324,7 @@
Loading
326 324
    type Error = S::Error;
327 325
    type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
328 326
329 -
    fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
330 -
        self.service.poll_ready(cx)
331 -
    }
327 +
    actix_service::forward_ready!(service);
332 328
333 329
    /// On first request, a new session cookie is returned in response, regardless
334 330
    /// of whether any session state is set.  With subsequent requests, if the

@@ -152,8 +152,8 @@
Loading
152 152
    actix_service::forward_ready!(service);
153 153
154 154
    fn call(&self, mut req: ServiceRequest) -> Self::Future {
155 -
        let srv = self.service.clone();
156 -
        let inner = self.inner.clone();
155 +
        let srv = Rc::clone(&self.service);
156 +
        let inner = Rc::clone(&self.inner);
157 157
158 158
        Box::pin(async move {
159 159
            let state = inner.load(&req).await?;

@@ -12,7 +12,7 @@
Loading
12 12
//! To access current request identity
13 13
//! [**Identity**](struct.Identity.html) extractor should be used.
14 14
//!
15 -
//! ```rust
15 +
//! ```
16 16
//! use actix_web::*;
17 17
//! use actix_identity::{Identity, CookieIdentityPolicy, IdentityService};
18 18
//!
@@ -49,11 +49,7 @@
Loading
49 49
50 50
#![deny(rust_2018_idioms)]
51 51
52 -
use std::cell::RefCell;
53 -
use std::future::Future;
54 -
use std::rc::Rc;
55 -
use std::task::{Context, Poll};
56 -
use std::time::SystemTime;
52 +
use std::{future::Future, rc::Rc, time::SystemTime};
57 53
58 54
use actix_service::{Service, Transform};
59 55
use futures_util::future::{ok, FutureExt, LocalBoxFuture, Ready};
@@ -239,22 +235,22 @@
Loading
239 235
    fn new_transform(&self, service: S) -> Self::Future {
240 236
        ok(IdentityServiceMiddleware {
241 237
            backend: self.backend.clone(),
242 -
            service: Rc::new(RefCell::new(service)),
238 +
            service: Rc::new(service),
243 239
        })
244 240
    }
245 241
}
246 242
247 243
#[doc(hidden)]
248 244
pub struct IdentityServiceMiddleware<S, T> {
245 +
    service: Rc<S>,
249 246
    backend: Rc<T>,
250 -
    service: Rc<RefCell<S>>,
251 247
}
252 248
253 249
impl<S, T> Clone for IdentityServiceMiddleware<S, T> {
254 250
    fn clone(&self) -> Self {
255 251
        Self {
256 -
            backend: self.backend.clone(),
257 -
            service: self.service.clone(),
252 +
            backend: Rc::clone(&self.backend),
253 +
            service: Rc::clone(&self.service),
258 254
        }
259 255
    }
260 256
}
@@ -270,13 +266,11 @@
Loading
270 266
    type Error = Error;
271 267
    type Future = LocalBoxFuture<'static, Result<Self::Response, Self::Error>>;
272 268
273 -
    fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
274 -
        self.service.borrow_mut().poll_ready(cx)
275 -
    }
269 +
    actix_service::forward_ready!(service);
276 270
277 271
    fn call(&self, mut req: ServiceRequest) -> Self::Future {
278 -
        let srv = self.service.clone();
279 -
        let backend = self.backend.clone();
272 +
        let srv = Rc::clone(&self.service);
273 +
        let backend = Rc::clone(&self.backend);
280 274
        let fut = self.backend.from_request(&mut req);
281 275
282 276
        async move {
@@ -285,9 +279,7 @@
Loading
285 279
                    req.extensions_mut()
286 280
                        .insert(IdentityItem { id, changed: false });
287 281
288 -
                    // https://github.com/actix/actix-web/issues/1263
289 -
                    let fut = srv.borrow_mut().call(req);
290 -
                    let mut res = fut.await?;
282 +
                    let mut res = srv.call(req).await?;
291 283
                    let id = res.request().extensions_mut().remove::<IdentityItem>();
292 284
293 285
                    if let Some(id) = id {
@@ -1132,12 +1124,10 @@
Loading
1132 1124
1133 1125
        let srv = IdentityServiceMiddleware {
1134 1126
            backend: Rc::new(Ident),
1135 -
            service: Rc::new(RefCell::new(into_service(
1136 -
                |_: ServiceRequest| async move {
1137 -
                    actix_rt::time::sleep(std::time::Duration::from_secs(100)).await;
1138 -
                    Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
1139 -
                },
1140 -
            ))),
1127 +
            service: Rc::new(into_service(|_: ServiceRequest| async move {
1128 +
                actix_rt::time::sleep(std::time::Duration::from_secs(100)).await;
1129 +
                Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
1130 +
            })),
1141 1131
        };
1142 1132
1143 1133
        let srv2 = srv.clone();

@@ -1,8 +1,4 @@
Loading
1 -
use std::{
2 -
    convert::TryInto,
3 -
    rc::Rc,
4 -
    task::{Context, Poll},
5 -
};
1 +
use std::{convert::TryInto, rc::Rc};
6 2
7 3
use actix_web::{
8 4
    dev::{Service, ServiceRequest, ServiceResponse},
@@ -131,9 +127,7 @@
Loading
131 127
    type Error = Error;
132 128
    type Future = CorsMiddlewareServiceFuture<B>;
133 129
134 -
    fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
135 -
        self.service.poll_ready(cx)
136 -
    }
130 +
    actix_service::forward_ready!(service);
137 131
138 132
    fn call(&self, req: ServiceRequest) -> Self::Future {
139 133
        if self.inner.preflight && req.method() == Method::OPTIONS {

@@ -1,11 +1,6 @@
Loading
1 1
//! HTTP Authentication middleware.
2 2
3 -
use std::cell::RefCell;
4 -
use std::future::Future;
5 -
use std::marker::PhantomData;
6 -
use std::pin::Pin;
7 -
use std::rc::Rc;
8 -
use std::sync::Arc;
3 +
use std::{future::Future, marker::PhantomData, pin::Pin, rc::Rc, sync::Arc};
9 4
10 5
use actix_web::{
11 6
    dev::{Service, ServiceRequest, ServiceResponse, Transform},
@@ -134,7 +129,7 @@
Loading
134 129
135 130
    fn new_transform(&self, service: S) -> Self::Future {
136 131
        future::ok(AuthenticationMiddleware {
137 -
            service: Rc::new(RefCell::new(service)),
132 +
            service: Rc::new(service),
138 133
            process_fn: self.process_fn.clone(),
139 134
            _extractor: PhantomData,
140 135
        })
@@ -146,7 +141,7 @@
Loading
146 141
where
147 142
    T: AuthExtractor,
148 143
{
149 -
    service: Rc<RefCell<S>>,
144 +
    service: Rc<S>,
150 145
    process_fn: Arc<F>,
151 146
    _extractor: PhantomData<T>,
152 147
}
@@ -163,9 +158,7 @@
Loading
163 158
    type Error = S::Error;
164 159
    type Future = LocalBoxFuture<'static, Result<ServiceResponse<B>, Error>>;
165 160
166 -
    fn poll_ready(&self, ctx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
167 -
        self.service.borrow_mut().poll_ready(ctx)
168 -
    }
161 +
    actix_service::forward_ready!(service);
169 162
170 163
    fn call(&self, req: ServiceRequest) -> Self::Future {
171 164
        let process_fn = Arc::clone(&self.process_fn);
@@ -183,9 +176,8 @@
Loading
183 176
            // TODO: alter to remove ? operator; an error response is required for downstream
184 177
            // middleware to do their thing (eg. cors adding headers)
185 178
            let req = process_fn(req, credentials).await?;
186 -
            // Ensure `borrow_mut()` and `.await` are on separate lines or else a panic occurs.
187 -
            let fut = service.borrow_mut().call(req);
188 -
            fut.await
179 +
180 +
            service.call(req).await
189 181
        }
190 182
        .boxed_local()
191 183
    }
@@ -252,12 +244,10 @@
Loading
252 244
    #[actix_rt::test]
253 245
    async fn test_middleware_panic() {
254 246
        let middleware = AuthenticationMiddleware {
255 -
            service: Rc::new(RefCell::new(into_service(
256 -
                |_: ServiceRequest| async move {
257 -
                    actix_rt::time::sleep(std::time::Duration::from_secs(1)).await;
258 -
                    Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
259 -
                },
260 -
            ))),
247 +
            service: Rc::new(into_service(|_: ServiceRequest| async move {
248 +
                actix_rt::time::sleep(std::time::Duration::from_secs(1)).await;
249 +
                Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
250 +
            })),
261 251
            process_fn: Arc::new(|req, _: BearerAuth| async { Ok(req) }),
262 252
            _extractor: PhantomData,
263 253
        };
@@ -277,12 +267,10 @@
Loading
277 267
    #[actix_rt::test]
278 268
    async fn test_middleware_panic_several_orders() {
279 269
        let middleware = AuthenticationMiddleware {
280 -
            service: Rc::new(RefCell::new(into_service(
281 -
                |_: ServiceRequest| async move {
282 -
                    actix_rt::time::sleep(std::time::Duration::from_secs(1)).await;
283 -
                    Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
284 -
                },
285 -
            ))),
270 +
            service: Rc::new(into_service(|_: ServiceRequest| async move {
271 +
                actix_rt::time::sleep(std::time::Duration::from_secs(1)).await;
272 +
                Err::<ServiceResponse, _>(error::ErrorBadRequest("error"))
273 +
            })),
286 274
            process_fn: Arc::new(|req, _: BearerAuth| async { Ok(req) }),
287 275
            _extractor: PhantomData,
288 276
        };
Files Coverage
actix-cors 91.55%
actix-redis 82.47%
actix-session/src 89.67%
actix-web-httpauth/src 61.01%
actix-identity/src/lib.rs 95.94%
actix-protobuf/src/lib.rs 50.00%
Project Totals (29 files) 82.33%
1
comment: false
2

3
ignore: # ignore codecoverage on following paths
4
  - "**/examples"
5
  - ".github"
6
  - "**/*.md"
7
  - "**/*.toml"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading