interface documentation

class ISessionProcurer(Interface): (source)

Known implementations: klein.SessionProcurer

View In Hierarchy

An ISessionProcurer wraps an ISessionStore and can procure sessions that store, given HTTP request objects.

Method procureSession Retrieve a session using whatever technique is necessary.
def procureSession(request, forceInsecure=False): (source)

Retrieve a session using whatever technique is necessary.

If the request already identifies an existing session in the store, retrieve it. If not, create a new session and retrieve that.

Parameters
request:IRequestThe request to procure a session from.
forceInsecure:boolEven if the request was transmitted securely (i.e. over HTTPS), retrieve the session that would be used by the same browser if it were sending an insecure (i.e. over HTTP) request; by default, this is False, and the session's security will match that of the request.
Returns
Deferred

a Deferred that:

  • fires with an ISession provider if the request describes an existing, valid session, or, if the intersection of the data in the request and the configuration of this ISessionProcurer allow for a cookie to be set immediately, or
  • fails with NoSuchSession if the request is unable to negotiate a session based on the current request: this is generally if the client is trying to use header-based authentication (and therefore does not want a new cookie set) or if this procurer is configured not to automatically create new sessions on the fly, or
  • fails with TooLateForCookies if the request bound to this procurer has already sent the headers and therefore we can no longer set a cookie, and we need to set a cookie.