1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

refactor service registration process; unify services and resources

This commit is contained in:
Nikolay Kim
2019-03-06 15:47:15 -08:00
parent 5cde4dc479
commit fe22e83144
18 changed files with 845 additions and 779 deletions

View File

@ -174,7 +174,7 @@ impl CookieSessionInner {
///
/// ```rust
/// use actix_session::CookieSession;
/// use actix_web::{App, HttpResponse, HttpServer};
/// use actix_web::{web, App, HttpResponse, HttpServer};
///
/// fn main() {
/// let app = App::new().middleware(
@ -183,7 +183,7 @@ impl CookieSessionInner {
/// .name("actix_session")
/// .path("/")
/// .secure(true))
/// .resource("/", |r| r.to(|| HttpResponse::Ok()));
/// .service(web::resource("/").to(|| HttpResponse::Ok()));
/// }
/// ```
pub struct CookieSession(Rc<CookieSessionInner>);
@ -314,19 +314,17 @@ where
#[cfg(test)]
mod tests {
use super::*;
use actix_web::{test, App};
use actix_web::{test, web, App};
#[test]
fn cookie_session() {
let mut app = test::init_service(
App::new()
.middleware(CookieSession::signed(&[0; 32]).secure(false))
.resource("/", |r| {
r.to(|ses: Session| {
let _ = ses.set("counter", 100);
"test"
})
}),
.service(web::resource("/").to(|ses: Session| {
let _ = ses.set("counter", 100);
"test"
})),
);
let request = test::TestRequest::get().to_request();
@ -342,12 +340,10 @@ mod tests {
let mut app = test::init_service(
App::new()
.middleware(CookieSession::signed(&[0; 32]).secure(false))
.resource("/", |r| {
r.to(|ses: Session| {
let _ = ses.set("counter", 100);
"test"
})
}),
.service(web::resource("/").to(|ses: Session| {
let _ = ses.set("counter", 100);
"test"
})),
);
let request = test::TestRequest::get().to_request();

View File

@ -13,7 +13,7 @@
//! extractor allows us to get or set session data.
//!
//! ```rust
//! use actix_web::{App, HttpServer, HttpResponse, Error};
//! use actix_web::{web, App, HttpServer, HttpResponse, Error};
//! use actix_session::{Session, CookieSession};
//!
//! fn index(session: Session) -> Result<&'static str, Error> {
@ -29,19 +29,17 @@
//! }
//!
//! fn main() -> std::io::Result<()> {
//! let sys = actix_rt::System::new("example"); // <- create Actix runtime
//!
//! # std::thread::spawn(||
//! HttpServer::new(
//! || App::new().middleware(
//! CookieSession::signed(&[0; 32]) // <- create cookie based session middleware
//! .secure(false)
//! )
//! .resource("/", |r| r.to(|| HttpResponse::Ok())))
//! .service(web::resource("/").to(|| HttpResponse::Ok())))
//! .bind("127.0.0.1:59880")?
//! .start();
//! # actix_rt::System::current().stop();
//! sys.run();
//! Ok(())
//! .run()
//! # );
//! # Ok(())
//! }
//! ```
use std::cell::RefCell;