示例#1
0
def cookies_middleware(environ, start_response):
    '''Parse the ``HTTP_COOKIE`` key in the *environ*. The ``HTTP_COOKIE``
string is replaced with a dictionary.'''
    c = environ.get('HTTP_COOKIE', '')
    if not isinstance(c, dict):
        if not c:
            c = {}
        else:
            if not isinstance(c, str):
                c = c.encode('utf-8')
            c = parse_cookie(c)
        environ['HTTP_COOKIE'] = c
示例#2
0
文件: plugins.py 项目: japaks/pulsar
def handle_cookies(response):
    headers = response.headers
    request = response.request
    client = request.client
    if 'set-cookie' in headers or 'set-cookie2' in headers:
        response._cookies = cookies = {}
        for cookie in (headers.get('set-cookie2'), headers.get('set-cookie')):
            if cookie:
                cookies.update(parse_cookie(cookie))
        if client.store_cookies:
            client.cookies.extract_cookies(response, request)
    return response
示例#3
0
def handle_cookies(response):
    headers = response.headers
    request = response.request
    client = request.client
    if 'set-cookie' in headers or 'set-cookie2' in headers:
        response._cookies = cookies = {}
        for cookie in (headers.get('set-cookie2'),
                       headers.get('set-cookie')):
            if cookie:
                cookies.update(parse_cookie(cookie))
        if client.store_cookies:
            client.cookies.extract_cookies(response, request)
    return response
示例#4
0
文件: tools.py 项目: japaks/pulsar
 def test_parse_cookie(self):
     self.assertEqual(parse_cookie('invalid key=true'), {'key': 'true'})
     self.assertEqual(parse_cookie('invalid;key=true'), {'key': 'true'})
     self.assertEqual(parse_cookie(''), {})
     self.assertEqual(parse_cookie(None), {})
     c = SimpleCookie()
     c.load('key=true')
     self.assertEqual(parse_cookie(c), {'key': 'true'})
     self.assertEqual(parse_cookie('key='), {'key': ''})
示例#5
0
 def test_parse_cookie(self):
     self.assertEqual(parse_cookie('invalid key=true'),
                      {'key':'true'})
     self.assertEqual(parse_cookie('invalid;key=true'),
                      {'key':'true'})
     self.assertEqual(parse_cookie(''), {})
     self.assertEqual(parse_cookie(None), {})
     c = SimpleCookie()
     c.load('key=true')
     self.assertEqual(parse_cookie(c), {'key':'true'})
     self.assertEqual(parse_cookie('key='), {'key': ''})
示例#6
0
def cookies_middleware(environ, start_response=None):
    """Parse the ``HTTP_COOKIE`` key in ``environ``.

    Set the new ``http.cookie`` key in ``environ`` with a dictionary
    of cookies obtained via the :func:`pulsar.utils.httpurl.parse_cookie`
    function.
    """
    c = environ.get("http.cookie")
    if not isinstance(c, dict):
        c = environ.get("HTTP_COOKIE", "")
        if not c:
            c = {}
        else:
            if not isinstance(c, str):
                c = c.encode("utf-8")
            c = parse_cookie(c)
        environ["http.cookie"] = c
示例#7
0
def cookies_middleware(environ, start_response=None):
    '''Parse the ``HTTP_COOKIE`` key in ``environ``.

    Set the new ``http.cookie`` key in ``environ`` with a dictionary
    of cookies obtained via the :func:`pulsar.utils.httpurl.parse_cookie`
    function.
    '''
    c = environ.get('http.cookie')
    if not isinstance(c, dict):
        c = environ.get('HTTP_COOKIE', '')
        if not c:
            c = {}
        else:
            if not isinstance(c, str):
                c = c.encode('utf-8')
            c = parse_cookie(c)
        environ['http.cookie'] = c
示例#8
0
def cookies_middleware(environ, start_response=None):
    '''Parse the ``HTTP_COOKIE`` key in ``environ``.

    Set the new ``http.cookie`` key in ``environ`` with a dictionary
    of cookies obtained via the :func:`pulsar.utils.httpurl.parse_cookie`
    function.
    '''
    c = environ.get('http.cookie')
    if not isinstance(c, dict):
        c = environ.get('HTTP_COOKIE', '')
        if not c:
            c = {}
        else:
            if not isinstance(c, str):
                c = c.encode('utf-8')
            c = parse_cookie(c)
        environ['http.cookie'] = c
示例#9
0
文件: httpurl.py 项目: cyberj/pulsar
 def test_parse_cookie(self):
     self.assertEqual(httpurl.parse_cookie('invalid key=true'),
                      {'key':'true'})
     self.assertEqual(httpurl.parse_cookie('invalid;key=true'),
                      {'key':'true'})