koajs / generic-session

koa session store with memory, redis or others.
MIT License
414 stars 65 forks source link

Don't generate new session for Websocket #86

Closed Zensey closed 4 years ago

Zensey commented 8 years ago

Forbid generating new session when being invoked from websocket session. Use case: using this middleware from koa-websocket.

coveralls commented 8 years ago

Coverage Status

Coverage decreased (-0.4%) to 95.885% when pulling 4e537b384e0ba734b94960d9a1643ee7bc5b2a17 on Zensey:master into a7b86cbeef5a5da765401493ee67472a26a277bf on koajs:master.

dead-horse commented 8 years ago

can you explain the impact if we generate new session for websocket?

Zensey commented 8 years ago

Nothing will broke, but session will be wasted.

In websocket session there is no response object, its not http connection whith request and responce. there is only upgradeReq object, so cookie will come to nowhere.

If I have no session, created earlier during http transaction, new session will be generated each time I connect to websocket.

There is the only goal of invoking generic-session middleware from websocket: to reuse http-generated session and session objects.

Example how I invoke middleware when websocket connect:

try {
    var ctx = koa.createContext(client.upgradeReq, {statusCode: null});
    yield generic_session.bind(ctx)(noop);
}
niftylettuce commented 4 years ago

Can you add a test? Not sure if you still use this.