aboutsummaryrefslogtreecommitdiff
path: root/cgi
diff options
context:
space:
mode:
authorLibravatar TOW 2019-04-03 07:57:25 -0300
committerLibravatar TOW 2019-04-03 08:03:24 -0300
commitccb5b163ea33a956b56d97812798212eb2a40c4f (patch)
tree55dc0f8037925a2abfc4985c5117ad6c85e6b711 /cgi
parent96c38d09a549ccc2887e83ff17107db1ace08e8a (diff)
downloadweabot-ccb5b163ea33a956b56d97812798212eb2a40c4f.tar.gz
weabot-ccb5b163ea33a956b56d97812798212eb2a40c4f.tar.xz
weabot-ccb5b163ea33a956b56d97812798212eb2a40c4f.zip
Arreglado viejo y horrible bug con cookies (#4)
Todas las cookies se estaban enviando de nuevo por cada request lo que hacía que el navegador se llenara de cookies en distintos dominios. Este bug viene dede allá por el 2010, lo encontré de pura suerte.
Diffstat (limited to 'cgi')
-rw-r--r--cgi/framework.py35
-rwxr-xr-xcgi/weabot.py7
2 files changed, 23 insertions, 19 deletions
diff --git a/cgi/framework.py b/cgi/framework.py
index 053bef0..2cfabe3 100644
--- a/cgi/framework.py
+++ b/cgi/framework.py
@@ -314,7 +314,10 @@ def getRandomIco():
def N_(message): return message
def getCookie(self, value=""):
- return urllib.unquote_plus(self._cookies[value].value)
+ try:
+ return urllib.unquote_plus(self._cookies[value].value)
+ except KeyError:
+ return None
def reCookie(self, key, value=""):
board = Settings._.BOARD
@@ -324,14 +327,14 @@ def setCookie(self, key, value="", max_age=None, expires=None, path="/", domain=
"""
Copied from Colubrid
"""
- if self._cookies is None:
- self._cookies = SimpleCookie()
- self._cookies[key] = urllib.quote_plus(value)
+ if self._newcookies is None:
+ self._newcookies = SimpleCookie()
+ self._newcookies[key] = urllib.quote_plus(value)
if not max_age is None:
- self._cookies[key]["max-age"] = max_age
+ self._newcookies[key]["max-age"] = max_age
if not expires is None:
if isinstance(expires, basestring):
- self._cookies[key]["expires"] = expires
+ self._newcookies[key]["expires"] = expires
expires = None
elif isinstance(expires, datetime):
expires = expires.utctimetuple()
@@ -350,26 +353,26 @@ def setCookie(self, key, value="", max_age=None, expires=None, path="/", domain=
)
d = "%s, %s %02d:%02d:%02d GMT" % (day, date, now.tm_hour,
now.tm_min, now.tm_sec)
- self._cookies[key]["expires"] = d
+ self._newcookies[key]["expires"] = d
if not path is None:
- self._cookies[key]["path"] = path
+ self._newcookies[key]["path"] = path
if not domain is None:
if domain != "THIS":
- self._cookies[key]["domain"] = domain
+ self._newcookies[key]["domain"] = domain
else:
- self._cookies[key]["domain"] = Settings.DOMAIN
+ self._newcookies[key]["domain"] = Settings.DOMAIN
if not secure is None:
- self._cookies[key]["secure"] = secure
+ self._newcookies[key]["secure"] = secure
def deleteCookie(self, key):
"""
Copied from Colubrid
"""
- if self._cookies is None:
- self._cookies = SimpleCookie()
- if not key in self._cookies:
- self._cookies[key] = ""
- self._cookies[key]["max-age"] = 0
+ if self._newcookies is None:
+ self._newcookies = SimpleCookie()
+ if not key in self._newcookies:
+ self._newcookies[key] = ""
+ self._newcookies[key]["max-age"] = 0
def elapsed_time(seconds, suffixes=['y','w','d','h','m','s'], add_s=False, separator=' '):
"""
diff --git a/cgi/weabot.py b/cgi/weabot.py
index f5451d9..f576f91 100755
--- a/cgi/weabot.py
+++ b/cgi/weabot.py
@@ -110,13 +110,14 @@ class weabot(object):
self.handleCookies()
def handleResponse(self):
- if self._cookies is not None:
- for cookie in self._cookies.values():
- self.headers.append(("Set-Cookie", cookie.output(header="")))
+ if self._newcookies:
+ for newcookie in self._newcookies.values():
+ self.headers.append(("Set-Cookie", newcookie.output(header="")))
def handleCookies(self):
self._cookies = SimpleCookie()
self._cookies.load(self.environ.get("HTTP_COOKIE", ""))
+ self._newcookies = None
def run(self):
path_split = self.environ["PATH_INFO"].split("/")