session property

  1. @override
HttpSession? get session
override

The user's HTTP session, created on first access if the client did not send the id of an existing one.

A new session's id reaches the client in a DARTSESSID cookie, which can only go out with the response headers: read this before an unbuffered response starts its body, or the session is lost.

Implementation

@override
HttpSession? get session {
  if (_session == null && _createSession != null && _headersSent) {
    app?.logger.warning(
      'A session was created after the response headers were sent, so the '
      'client will not get its DARTSESSID cookie. Read req.session before '
      'writing the response body.',
    );
    // Usable for the rest of this request, but not kept: no client can
    // send its id back, so storing it would only fill the session store.
    return _session = _createSession!(store: false);
  }
  return _session ??= _createSession?.call();
}