axum-sessions icon indicating copy to clipboard operation
axum-sessions copied to clipboard

Add a listener trait to listen to the creation, update and destruction of sessions

Open octoape opened this issue 2 years ago • 3 comments

Add a listener trait to listen to the creation, update and destruction of sessions

octoape avatar Apr 26 '23 04:04 octoape

Thanks for the suggestion. Do you have an idea of what the implementation would look like?

maxcountryman avatar Apr 30 '23 16:04 maxcountryman

I think it should be similar to the listener API of the javaee servlet

trait SessionListener {
  fn onSessionCreated(self: Self, event: SessionEvent);
  fn onSessionDestoryed(self: Self, event: SessionEvent);
  fn onAttributeAdded(self: Self, event: SessionAttributeEvent);
  fn onAttributeReplaced(self: Self, event: SessionAttributeEvent);
  fn onAttributeRemoved(self: Self, event: SessionAttributeEvent);
}

octoape avatar May 17 '23 04:05 octoape

I suggest a slightly different interface:

pub enum AttributeEvent {
    Add(AddEvent),
    Replace(ReplaceEvent),
    Remove(RemoveEvent)
}

pub enum SessionEvent {
    Create(CreateEvent),
    Destroy(DestroyEvent),
    Modify(AttributeEvent)
}

trait SessionListener {
    fn onEvent(&self, event: SessionEvent);
}

czocher avatar Jun 17 '23 23:06 czocher