Struct fe_session::FeSessionStorage [] [src]

pub struct FeSessionStorage<T: 'static> {
    // some fields omitted
}

Storage object that holds the mapping of session IDs to sessions.

This class is inserted into the iron handler change to provide session functionality to your application.

Examples

use iron::{Iron, Request, Response};
use iron::middleware::Chain;
use iron::status::Status;
use fe_session::{FeSessionRequest, FeSessionStorage, FeConnection};

struct MySession  {
    name : String
}

let mut chain = Chain::new(|req : &mut Request| {
    if req.url.path()[0] == "login" {
        let name = String::from(req.url.query().unwrap());

        req.create_session(MySession {
            name : name
        });
        Ok(Response::with((Status::Ok, "Hello")))
    }
    else if req.url.path()[0] == "logout" {
       req.clear_session::<MySession>();
       Ok(Response::with((Status::Ok, "Goodbye")))
    }
    else {
        let mut access = req.get_session::<MySession>();

        if access.state().is_active() {
            let session = access.get();
            Ok(Response::with((Status::Ok, session.name.clone())))
        } else {
            Ok(Response::with((Status::Ok, "I don't know you.")))
        }
    }
});

chain.around(FeSessionStorage::<MySession>::new());

let mut iron = Iron::new(chain).http(("localhost", 3000)).unwrap();

let mut conn = FeConnection::new("localhost", 3000);
assert_eq!(conn.get_string("/login?bob"), "Hello");
assert_eq!(conn.get_string("/"), "bob");
assert_eq!(conn.get_string("/logout"), "Goodbye");
assert_eq!(conn.get_string("/"), "I don't know you.");

iron.close().unwrap();

Methods

impl<T: Any + Send + Sync> FeSessionStorage<T>

fn new() -> FeSessionStorage<T>

Create a new instance with default session values. Please refer to FeSessionConfig::new() for what the default values are.

Returns the newly created instance.

fn create(config: FeSessionConfig) -> FeSessionStorage<T>

Create a new instance with custom configuration values.

Returns the newly created instance.

Examples

use fe_session::{FeSessionConfig, FeSessionStorage};

struct MySession;

let config = FeSessionConfig::new();

let sessions = FeSessionStorage::<MySession>::create(config);

Trait Implementations

impl<T: Any + Send + Sync> AroundMiddleware for FeSessionStorage<T>

fn around(self, handler: Box<Handler>) -> Box<Handler>

impl<T: Any + Send + Sync> BeforeMiddleware for FeSessionStorage<T>

fn before(&self, request: &mut Request) -> IronResult<()>

fn catch(&self, &mut Request, err: IronError) -> Result<(), IronError>

impl<T: Any + Send + Sync> AfterMiddleware for FeSessionStorage<T>

fn after(&self, request: &mut Request, response: Response) -> IronResult<Response>

fn catch(&self, &mut Request, err: IronError) -> Result<Response, IronError>

impl<T> Drop for FeSessionStorage<T>

fn drop(&mut self)

impl<T> Clone for FeSessionStorage<T>

fn clone(&self) -> FeSessionStorage<T>

fn clone_from(&mut self, source: &FeSessionStorage<T>)

impl<T> Debug for FeSessionStorage<T>

fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error>