@@ -46,6 +46,17 @@ class WebClient(object):
|
|||||||
self.default_headers = default_headers
|
self.default_headers = default_headers
|
||||||
self.sessions = {}
|
self.sessions = {}
|
||||||
self.session_regex = session_regex and re.compile(session_regex)
|
self.session_regex = session_regex and re.compile(session_regex)
|
||||||
|
self.headers = {}
|
||||||
|
|
||||||
|
def _parse_headers_in_cookies(self):
|
||||||
|
self.cookies = {}
|
||||||
|
if 'set-cookie' in self.headers:
|
||||||
|
for item in self.headers['set-cookie'].split(','):
|
||||||
|
cookie = item[:item.find(';')]
|
||||||
|
pos = cookie.find('=')
|
||||||
|
key = cookie[:pos]
|
||||||
|
value = cookie[pos+1:]
|
||||||
|
self.cookies[key.strip()] = value.strip()
|
||||||
|
|
||||||
def get(self, url, cookies=None, headers=None, auth=None):
|
def get(self, url, cookies=None, headers=None, auth=None):
|
||||||
return self.post(url, data=None, cookies=cookies,
|
return self.post(url, data=None, cookies=cookies,
|
||||||
@@ -149,12 +160,7 @@ class WebClient(object):
|
|||||||
else:
|
else:
|
||||||
raise error
|
raise error
|
||||||
|
|
||||||
# parse headers into cookies
|
self._parse_headers_in_cookies()
|
||||||
self.cookies = {}
|
|
||||||
if 'set-cookie' in self.headers:
|
|
||||||
for item in self.headers['set-cookie'].split(','):
|
|
||||||
key, value = item[:item.find(';')].split('=')
|
|
||||||
self.cookies[key.strip()] = value.strip()
|
|
||||||
|
|
||||||
# check is a new session id has been issued, symptom of broken session
|
# check is a new session id has been issued, symptom of broken session
|
||||||
if self.session_regex is not None:
|
if self.session_regex is not None:
|
||||||
|
|||||||
@@ -49,6 +49,24 @@ def stopwebserver():
|
|||||||
webserverprocess.terminate()
|
webserverprocess.terminate()
|
||||||
|
|
||||||
|
|
||||||
|
class Cookie(unittest.TestCase):
|
||||||
|
def testParseMultipleEquals(self):
|
||||||
|
""" Test for issue #1500.
|
||||||
|
Ensure that a cookie containing one or more '=' is correctly parsed
|
||||||
|
"""
|
||||||
|
client = WebClient()
|
||||||
|
client.headers['set-cookie'] = "key = value with one =;"
|
||||||
|
client._parse_headers_in_cookies()
|
||||||
|
self.assertIn("key", client.cookies)
|
||||||
|
self.assertEqual(client.cookies['key'], "value with one =")
|
||||||
|
|
||||||
|
client.headers['set-cookie'] = "key = value with one = and another one =;"
|
||||||
|
client._parse_headers_in_cookies()
|
||||||
|
client._parse_headers_in_cookies()
|
||||||
|
self.assertIn("key", client.cookies)
|
||||||
|
self.assertEqual(client.cookies['key'], "value with one = and another one =")
|
||||||
|
|
||||||
|
|
||||||
class LiveTest(unittest.TestCase):
|
class LiveTest(unittest.TestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
Reference in New Issue
Block a user