Skip to content

Commit

Permalink
Optimize cycle in CookieJar
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Aug 6, 2016
1 parent b7a2427 commit dd4a6e5
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ def filter_cookies(self, request_url):
"""Returns this jar's cookies filtered by their attributes."""
url_parsed = urlsplit(request_url)
filtered = SimpleCookie()
hostname = url_parsed.hostname or ""
is_not_secure = url_parsed.scheme not in ("https", "wss")

for name, cookie in self._cookies.items():
cookie_domain = cookie["domain"]
Expand All @@ -704,8 +706,6 @@ def filter_cookies(self, request_url):
dict.__setitem__(filtered, name, cookie)
continue

hostname = url_parsed.hostname or ""

if not self._unsafe and is_ip_address(hostname):
continue

Expand All @@ -718,9 +718,7 @@ def filter_cookies(self, request_url):
if not self._is_path_match(url_parsed.path, cookie["path"]):
continue

is_secure = url_parsed.scheme in ("https", "wss")

if cookie["secure"] and not is_secure:
if is_not_secure and cookie["secure"]:
continue

dict.__setitem__(filtered, name, cookie)
Expand Down

0 comments on commit dd4a6e5

Please sign in to comment.