From 3627fb540b1cf6e76525a7ff662d131f56150b1b Mon Sep 17 00:00:00 2001 From: Mike Thompson Date: Mon, 29 Aug 2011 21:18:35 -0700 Subject: [PATCH] add 'cookies' property to wsgi.HTTPRequest --- tornado/wsgi.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tornado/wsgi.py b/tornado/wsgi.py index fb8bd4967..e8f878bb4 100644 --- a/tornado/wsgi.py +++ b/tornado/wsgi.py @@ -29,6 +29,7 @@ provides WSGI support in two ways: and Tornado handlers in a single server. """ +import Cookie import cgi import httplib import logging @@ -159,6 +160,19 @@ class HTTPRequest(object): """Returns True if this request supports HTTP/1.1 semantics""" return self.version == "HTTP/1.1" + @property + def cookies(self): + """A dictionary of Cookie.Morsel objects.""" + if not hasattr(self, "_cookies"): + self._cookies = Cookie.SimpleCookie() + if "Cookie" in self.headers: + try: + self._cookies.load( + native_str(self.headers["Cookie"])) + except Exception: + self._cookies = None + return self._cookies + def full_url(self): """Reconstructs the full URL for this request.""" return self.protocol + "://" + self.host + self.uri -- 2.47.2