Skip to content

Experimental cookie session middleware and extractor for the tide web framework.

Notifications You must be signed in to change notification settings

tomhoule/tide-cookie-session

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tide-session

This is an experimental middleware and extractor for cookie-based sessions within the tide framework.

It only stores a session id in a cookie, and relies on a configurable session store (implementing the SessionStorage trait)

Examples

Setting the middleware

    let state: InMemorySession<()> = InMemorySession::new();
    app.middleware(CookieSessionMiddleware::new("MySession".to_string(), state));

Reading the contents of the session

async fn print_session(session: Session<AppSession>) -> Response {
    let session: Option<AppSession> = await! { session.get() }.unwrap();
    let printed_session = format!("{:?}", session);
    let res = Response::new(printed_session.into());
    res
}

Modiying the contents of the session

async fn authenticate_user(session: Session<AppSession>) -> Response {
    let res = Response::new(Body::empty());

    let result: Result<(), failure::Error> = await! { session.set(AppSession {
        user_id: "george".into(),
        user_category: UserCategory::Admin,
    }) };

    res
}

For a more complete example, read the tests in tests/cookies.rs.

TODO

  • session id reset
  • documentation
  • general polish, more tests
  • more backends
  • Signed and encrypted cookies, more configurable cookies.

About

Experimental cookie session middleware and extractor for the tide web framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages