Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to create a custom HttpServer session manager that allows persistence #16502

Closed
DartBot opened this issue Feb 3, 2014 · 9 comments
Closed
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-stale Closed as the issue or PR is assumed stale library-io type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Feb 3, 2014

This issue was originally filed by sfesc...@gmail.com


The ability to plug in a custom HttpSessionManager would allow for persistent session management. This is needed for clustered and distributed sessions.

What would be needed is the ability to create a custom session manager that (in addition to current HttpSessionManager's interface) is invoked to:

  1. Future<HttpSession> getSession (complete before processing the request)
  2. Future storeSession (invoked after the response is "done")
  3. Future invalidateSession (invoked if the session is invalidated)

Additionally, the HttpRequest should get the _DART_SESSION_ID from the sessionManagerInstance rather then hardcoded.

@andersjohnsen
Copy link

Added Area-IO, Triaged labels.

@sgjesse
Copy link
Contributor

sgjesse commented Feb 3, 2014

Justin I know you have some ideas for this.


cc @justinfagnani.

@justinfagnani
Copy link
Contributor

I think there are two responsibilities here, managing the session cookie and managing the session state.

Managing the cookie is hopefully doable with a simple callback. There's questions about how much of the request/response interface it needs access to, and how it's parameterized, but a starting point could just be:

typedef String SessionCookieCallback(HttpRequest request, {bool create, Duration timeout});

I'm pretty sure that just establishing the session cookie can be synchronous. Associating the session ID with an actual session should be async.

abstract class HttpSessionManager {
  // retrieves a session by ID, creating it if non exists and [create] is true.
  Future<HttpSession> getSession(String sessionId, {bool create});
  
  Future<bool> removeSession(String sessionId);

  // saves a session to the backing store
  Future<bool> saveSession(HttpSession session);

  /// Tells the manager to persist all unsaved sessions to the backing store
  Future<bool> saveAll();
}

Then let the manage be registered, and provide an async method to get the session:

HttpServer {

  addSessionManager(RequestMatcher matcher, HttpSessionManager manager, {SessionCookieCallback cookieCallback});

  Future<HttpSession> getSession();
}

(I assume that we have a standard request matcher: typedef Future<bool> RequestMatcher(HttpRequest r); which is used to filter requests.)

@DartBot
Copy link
Author

DartBot commented Feb 3, 2014

This comment was originally written by sfesca...@gmail.com


I agree, I would add that creating the sessionId also needs to be async as a check in a persistent store for uniqueness may be required.

@kevmoo
Copy link
Member

kevmoo commented May 14, 2014

Removed Area-IO label.
Added Library-IO label.

@DartBot
Copy link
Author

DartBot commented Nov 7, 2014

This comment was originally written by miroslav.r...@gmail.com


Hi, can we expect implementation anytime soon? We'd like to use Dart on the server-side and it's really needed for production mode. Thanks!

@DartBot
Copy link
Author

DartBot commented Nov 7, 2014

This comment was originally written by @zoechi


What about shelf and shelf_auth (includes jwtSession)
https://pub.dartlang.org/packages/shelf_auth

@DartBot
Copy link
Author

DartBot commented Nov 7, 2014

This comment was originally written by miroslav....@gmail.com


The problem that we need to solve are persistent sessions - use Redis adapter to store and retrieve sessions instead of storing them in memory. The goal is to use them seamlessly through request.session property.

shelf_auth looks like interesting project but (as far as I understand) it wouldn't allow me to inject custom session data into Request objects even if I write custom SessionHandler -- because it is not currently possible in the dart.io implementation. This is what this issue is trying to solve.

Of course, we could write our own persistent session manager and use it instead of accessing request.session objects. But it's not a nice solution, since there would be 2 simultaneous session management systems, 2 session ids in cookies, 2 ways to access sessions (but only one persistent, with no way to enforce usage of that one only), ...

@sgjesse
Copy link
Contributor

sgjesse commented Mar 24, 2015

Removed Type-Defect label.
Added Type-Enhancement label.

@kevmoo kevmoo added the area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. label Jun 16, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@lrhn lrhn closed this as completed Apr 8, 2024
@lrhn lrhn added the closed-stale Closed as the issue or PR is assumed stale label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-stale Closed as the issue or PR is assumed stale library-io type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants