Skip to content

Commit

Permalink
add 'cookies' property to wsgi.HTTPRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejthompson committed Aug 30, 2011
1 parent 129d77d commit 3627fb5
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tornado/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
and Tornado handlers in a single server.
"""

import Cookie
import cgi
import httplib
import logging
Expand Down Expand Up @@ -159,6 +160,19 @@ def supports_http_1_1(self):
"""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
Expand Down

0 comments on commit 3627fb5

Please sign in to comment.