'Check if there is a session cookie, and if not, create it.
By default, the cookie with be secure for HTTPS requests and not secure
for HTTP requests.  If for some reason you need access to the insecure
cookie from a secure request you can set C{forceNotSecure = True}.
@param forceNotSecure: Should we retrieve a session that will be
transmitted over HTTP, even if this L{Request} was delivered over
HTTPS?
@type forceNotSecure: L{bool}'

def getSession(self, sessionInterface=None, forceNotSecure=False):

    secure = (self.isSecure() and (not forceNotSecure))
    if (not secure):
        cookieString = 'TWISTED_SESSION'
        sessionAttribute = '_insecureSession'
    else:
        cookieString = 'TWISTED_SECURE_SESSION'
        sessionAttribute = '_secureSession'
    session = getattr(self, sessionAttribute)
    if (not session):
        cookiename = '_'.join(([cookieString] + self.sitepath))
        sessionCookie = self.getCookie(cookiename)
        if sessionCookie:
            try:
                session = self.site.getSession(sessionCookie)
            except KeyError:
                pass
        if (not session):
            session = self.site.makeSession()
            self.addCookie(cookiename, session.uid, path='/', secure=secure)
    session.touch()
    setattr(self, sessionAttribute, session)
    if sessionInterface:
        return session.getComponent(sessionInterface)
    return session
