Example #1
0
def test_wrapper_support():
    """Securecookie wrapper integration"""
    req = Request.from_values()
    resp = Response()
    c = SecureCookie.load_cookie(req, secret_key='foo')
    assert c.new
    c['foo'] = 42
    assert c.secret_key == 'foo'
    c.save_cookie(resp)

    req = Request.from_values(headers={
        'Cookie':  'session="%s"' % parse_cookie(resp.headers['set-cookie'])['session']
    })
    c2 = SecureCookie.load_cookie(req, secret_key='foo')
    assert not c2.new
    assert c2 == c
Example #2
0
    def __call__(self, environ, start_response):
        cookie = parse_cookie(environ.get('HTTP_COOKIE', ''))
        sid = cookie.get(self.cookie_name, None)
        if sid is None:
            session = self.store.new()
        else:
            session = self.store.get(sid)
        environ[self.environ_key] = session

        def injecting_start_response(status, headers, exc_info = None):
            if session.should_save:
                self.store.save(session)
                headers.append(('Set-Cookie', dump_cookie(self.cookie_name, session.sid, self.cookie_age, self.cookie_expires, self.cookie_path, self.cookie_domain, self.cookie_secure, self.cookie_httponly)))
            return start_response(status, headers, exc_info)

        return ClosingIterator(self.app(environ, injecting_start_response), lambda : self.store.save_if_modified(session))
Example #3
0
    def __call__(self, environ, start_response):
        cookie = parse_cookie(environ.get('HTTP_COOKIE', ''))
        sid = cookie.get(self.cookie_name, None)
        if sid is None:
            session = self.store.new()
        else:
            session = self.store.get(sid)
        environ[self.environ_key] = session

        def injecting_start_response(status, headers, exc_info=None):
            if session.should_save:
                self.store.save(session)
                headers.append(('Set-Cookie', dump_cookie(self.cookie_name,
                                session.sid, self.cookie_age,
                                self.cookie_expires, self.cookie_path,
                                self.cookie_domain, self.cookie_secure,
                                self.cookie_httponly)))
            return start_response(status, headers, exc_info)
        return ClosingIterator(self.app(environ, injecting_start_response),
                               lambda: self.store.save_if_modified(session))
Example #4
0
File: wsgi.py Project: jek/alfajor
 def cookies(self):
     if not self._referrer:
         return {}
     environ = self._create_environ(self._referrer, 'GET', None, True)
     return parse_cookie(environ, self._charset)