Skip to content

Commit

Permalink
bug fix in http cookies handling
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Aug 4, 2014
1 parent bfe377d commit 1bf0a21
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
script:
- python -m covrun --pep8 pulsar examples tests
- sudo rm -rf pulsar
- python -m covrun -w 1 --concurrent-tasks 1 --sequential --log-level none trollius.error pulsar.wsgi.none --verbosity 2 -e taskqueue pshell webmail stores.redis stores.query stores.odm.couchdb stores.odm.postgresql stores.odm.redis
- python -m covrun -w 2 --log-level none trollius.error -e taskqueue pshell webmail stores.redis stores.query stores.odm.couchdb stores.odm.postgresql stores.odm.redis
- if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then python -m runtests --coveralls; fi

notifications:
Expand Down
5 changes: 2 additions & 3 deletions pulsar/apps/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,9 @@ def __init__(self, client, url, method, inp_params, headers=None,
if self._scheme in tls_schemes:
self._ssl = client.ssl_context(**ignored)
self.headers = client.get_headers(self, headers)
if client.cookies:
client.cookies.add_cookie_header(self)
cookies = cookiejar_from_dict(client.cookies, cookies)
if cookies:
cookiejar_from_dict(cookies).add_cookie_header(self)
cookies.add_cookie_header(self)
self.unredirected_headers['host'] = host_no_default_port(self._scheme,
self._netloc)
client.set_proxy(self)
Expand Down
20 changes: 12 additions & 8 deletions pulsar/utils/httpurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1281,20 +1281,24 @@ def create_cookie(name, value, **kwargs):
return Cookie(**result)


def cookiejar_from_dict(cookie_dict, cookiejar=None):
def cookiejar_from_dict(*cookie_dicts):
"""Returns a CookieJar from a key/value dictionary.
:param cookie_dict: Dict of key/values to insert into CookieJar.
"""
if not isinstance(cookie_dict, CookieJar):
if cookiejar is None:
cookiejar = CookieJar()
if cookie_dict is not None:
jars = []
cookie_dicts = tuple((d for d in cookie_dicts if d))
if len(cookie_dicts) == 1 and isinstance(cookie_dicts[0], CookieJar):
return cookie_dicts[0]
cookiejar = CookieJar()
for cookie_dict in cookie_dicts:
if isinstance(cookie_dict, CookieJar):
for cookie in cookie_dict:
cookiejar.set_cookie(cookie)
else:
for name in cookie_dict:
cookiejar.set_cookie(create_cookie(name, cookie_dict[name]))
return cookiejar
else:
return cookie_dict
return cookiejar


cc_delim_re = re.compile(r'\s*,\s*')
Expand Down
3 changes: 2 additions & 1 deletion tests/http/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,8 @@ def test_send_cookie(self):
response = yield http.get(self.httpbin('cookies'), cookies=cookies)
self.assertEqual(response.status_code, 200)
data = response.decode_content()
self.assertEqual(data['cookies'], cookies)
self.assertEqual(data['cookies']['sessionid'], 't1')
self.assertEqual(data['cookies']['cookies_are'], 'working')

def test_cookie(self):
http = self._client
Expand Down

0 comments on commit 1bf0a21

Please sign in to comment.