New request.cookies property

This commit is contained in:
Simon Willison 2020-06-02 14:06:53 -07:00
commit 1d0bea157a
3 changed files with 12 additions and 7 deletions

View file

@ -4,6 +4,7 @@ from mimetypes import guess_type
from urllib.parse import parse_qs, urlunparse, parse_qsl
from pathlib import Path
from html import escape
from http.cookies import SimpleCookie
import re
import aiofiles
@ -44,6 +45,12 @@ class Request:
def host(self):
return self.headers.get("host") or "localhost"
@property
def cookies(self):
cookies = SimpleCookie()
cookies.load(self.headers.get("cookie", ""))
return {key: value.value for key, value in cookies.items()}
@property
def path(self):
if self.scope.get("raw_path") is not None: