Repository: encode/starlette

Issue:
[bug] Invalid cookie name leads to exception
When handling a request with an invalid cookie name (does not conform to RFC2109) starlette raises an exception. i.e iam/cookiename
This is because Starlette uses Python's stdlib cookie library, which is very strict.
I do understand the strictness, but in real life scenarios you receive such malformed cookies and I want to handle those requests.
My suggestion for a solution would be to catch those exceptions and ignore the invalid cookie. 
** EDIT **
I just realized stdlib is used for the whole cookie header, hence can't ignore only one cookie.
I'll create a PR for ignoring the whole cookie on such case, but maybe we should create our own Cookie/Morsel class and override the methods to ignore such error in the inbound case?

Discussion:

Patch:
diff --git a/docs/requests.md b/docs/requests.md
index f0ffc66..a72cb75 100644
--- a/docs/requests.md
+++ b/docs/requests.md
@@ -73,6 +73,8 @@ Cookies are exposed as a regular dictionary interface.
 
 For example: `request.cookies.get('mycookie')`
 
+Cookies are ignored in case of an invalid cookie. (RFC2109)
+
 #### Body
 
 There are a few different interfaces for returning the body of the request:
diff --git a/starlette/requests.py b/starlette/requests.py
index 1f7b09e..0ebeb3f 100644
--- a/starlette/requests.py
+++ b/starlette/requests.py
@@ -91,7 +91,10 @@ class HTTPConnection(Mapping):
             cookie_header = self.headers.get("cookie")
             if cookie_header:
                 cookie = http.cookies.SimpleCookie()  # type: http.cookies.BaseCookie
-                cookie.load(cookie_header)
+                try:
+                    cookie.load(cookie_header)
+                except http.cookies.CookieError:
+                    pass
                 for key, morsel in cookie.items():
                     cookies[key] = morsel.value
             self._cookies = cookies


Test patch:
diff --git a/tests/test_requests.py b/tests/test_requests.py
index defdf3a..3381249 100644
--- a/tests/test_requests.py
+++ b/tests/test_requests.py
@@ -285,6 +285,17 @@ def test_request_cookies():
     assert response.text == "Hello, cookies!"
 
 
+def test_invalid_cookie():
+    async def app(scope, receive, send):
+        request = Request(scope, receive)
+        response = JSONResponse({"cookies": request.cookies})
+        await response(scope, receive, send)
+
+    client = TestClient(app)
+    response = client.get("/", cookies={"invalid/cookie": "test", "valid": "test2"})
+    assert response.json() == {"cookies": {}}
+
+
 def test_chunked_encoding():
     async def app(scope, receive, send):
         request = Request(scope, receive)