We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `starlette/requests.py`
Content:
```
1 import asyncio
2 import http.cookies
3 import json
4 import typing
5 from collections.abc import Mapping
6 
7 from starlette.datastructures import URL, Address, FormData, Headers, QueryParams, State
8 from starlette.formparsers import FormParser, MultiPartParser
9 from starlette.types import Message, Receive, Scope, Send
10 
11 try:
12     from multipart.multipart import parse_options_header
13 except ImportError:  # pragma: nocover
14     parse_options_header = None
15 
16 
17 SERVER_PUSH_HEADERS_TO_COPY = {
18     "accept",
19     "accept-encoding",
20     "accept-language",
21     "cache-control",
22     "user-agent",
23 }
24 
25 
26 class ClientDisconnect(Exception):
27     pass
28 
29 
30 class HTTPConnection(Mapping):
31     """
32     A base class for incoming HTTP connections, that is used to provide
33     any functionality that is common to both `Request` and `WebSocket`.
34     """
35 
36     def __init__(self, scope: Scope, receive: Receive = None) -> None:
37         assert scope["type"] in ("http", "websocket")
38         self.scope = scope
39 
40     def __getitem__(self, key: str) -> str:
41         return self.scope[key]
42 
43     def __iter__(self) -> typing.Iterator[str]:
44         return iter(self.scope)
45 
46     def __len__(self) -> int:
47         return len(self.scope)
48 
49     @property
50     def app(self) -> typing.Any:
51         return self.scope["app"]
52 
53     @property
54     def url(self) -> URL:
55         if not hasattr(self, "_url"):
56             self._url = URL(scope=self.scope)
57         return self._url
58 
59     @property
60     def base_url(self) -> URL:
61         if not hasattr(self, "_base_url"):
62             base_url_scope = dict(self.scope)
63             base_url_scope["path"] = "/"
64             base_url_scope["query_string"] = b""
65             base_url_scope["root_path"] = base_url_scope.get(
66                 "app_root_path", base_url_scope.get("root_path", "")
67             )
68             self._base_url = URL(scope=base_url_scope)
69         return self._base_url
70 
71     @property
72     def headers(self) -> Headers:
73         if not hasattr(self, "_headers"):
74             self._headers = Headers(scope=self.scope)
75         return self._headers
76 
77     @property
78     def query_params(self) -> QueryParams:
79         if not hasattr(self, "_query_params"):
80             self._query_params = QueryParams(self.scope["query_string"])
81         return self._query_params
82 
83     @property
84     def path_params(self) -> dict:
85         return self.scope.get("path_params", {})
86 
87     @property
88     def cookies(self) -> typing.Dict[str, str]:
89         if not hasattr(self, "_cookies"):
90             cookies = {}
91             cookie_header = self.headers.get("cookie")
92             if cookie_header:
93                 cookie = http.cookies.SimpleCookie()  # type: http.cookies.BaseCookie
94                 cookie.load(cookie_header)
95                 for key, morsel in cookie.items():
96                     cookies[key] = morsel.value
97             self._cookies = cookies
98         return self._cookies
99 
100     @property
101     def client(self) -> Address:
102         host, port = self.scope.get("client") or (None, None)
103         return Address(host=host, port=port)
104 
105     @property
106     def session(self) -> dict:
107         assert (
108             "session" in self.scope
109         ), "SessionMiddleware must be installed to access request.session"
110         return self.scope["session"]
111 
112     @property
113     def auth(self) -> typing.Any:
114         assert (
115             "auth" in self.scope
116         ), "AuthenticationMiddleware must be installed to access request.auth"
117         return self.scope["auth"]
118 
119     @property
120     def user(self) -> typing.Any:
121         assert (
122             "user" in self.scope
123         ), "AuthenticationMiddleware must be installed to access request.user"
124         return self.scope["user"]
125 
126     @property
127     def state(self) -> State:
128         if not hasattr(self, "_state"):
129             # Ensure 'state' has an empty dict if it's not already populated.
130             self.scope.setdefault("state", {})
131             # Create a state instance with a reference to the dict in which it should store info
132             self._state = State(self.scope["state"])
133         return self._state
134 
135     def url_for(self, name: str, **path_params: typing.Any) -> str:
136         router = self.scope["router"]
137         url_path = router.url_path_for(name, **path_params)
138         return url_path.make_absolute_url(base_url=self.base_url)
139 
140 
141 async def empty_receive() -> Message:
142     raise RuntimeError("Receive channel has not been made available")
143 
144 
145 async def empty_send(message: Message) -> None:
146     raise RuntimeError("Send channel has not been made available")
147 
148 
149 class Request(HTTPConnection):
150     def __init__(
151         self, scope: Scope, receive: Receive = empty_receive, send: Send = empty_send
152     ):
153         super().__init__(scope)
154         assert scope["type"] == "http"
155         self._receive = receive
156         self._send = send
157         self._stream_consumed = False
158         self._is_disconnected = False
159 
160     @property
161     def method(self) -> str:
162         return self.scope["method"]
163 
164     @property
165     def receive(self) -> Receive:
166         return self._receive
167 
168     async def stream(self) -> typing.AsyncGenerator[bytes, None]:
169         if hasattr(self, "_body"):
170             yield self._body
171             yield b""
172             return
173 
174         if self._stream_consumed:
175             raise RuntimeError("Stream consumed")
176 
177         self._stream_consumed = True
178         while True:
179             message = await self._receive()
180             if message["type"] == "http.request":
181                 body = message.get("body", b"")
182                 if body:
183                     yield body
184                 if not message.get("more_body", False):
185                     break
186             elif message["type"] == "http.disconnect":
187                 self._is_disconnected = True
188                 raise ClientDisconnect()
189         yield b""
190 
191     async def body(self) -> bytes:
192         if not hasattr(self, "_body"):
193             chunks = []
194             async for chunk in self.stream():
195                 chunks.append(chunk)
196             self._body = b"".join(chunks)
197         return self._body
198 
199     async def json(self) -> typing.Any:
200         if not hasattr(self, "_json"):
201             body = await self.body()
202             self._json = json.loads(body)
203         return self._json
204 
205     async def form(self) -> FormData:
206         if not hasattr(self, "_form"):
207             assert (
208                 parse_options_header is not None
209             ), "The `python-multipart` library must be installed to use form parsing."
210             content_type_header = self.headers.get("Content-Type")
211             content_type, options = parse_options_header(content_type_header)
212             if content_type == b"multipart/form-data":
213                 multipart_parser = MultiPartParser(self.headers, self.stream())
214                 self._form = await multipart_parser.parse()
215             elif content_type == b"application/x-www-form-urlencoded":
216                 form_parser = FormParser(self.headers, self.stream())
217                 self._form = await form_parser.parse()
218             else:
219                 self._form = FormData()
220         return self._form
221 
222     async def close(self) -> None:
223         if hasattr(self, "_form"):
224             await self._form.close()
225 
226     async def is_disconnected(self) -> bool:
227         if not self._is_disconnected:
228             try:
229                 message = await asyncio.wait_for(self._receive(), timeout=0.0000001)
230             except asyncio.TimeoutError:
231                 message = {}
232 
233             if message.get("type") == "http.disconnect":
234                 self._is_disconnected = True
235 
236         return self._is_disconnected
237 
238     async def send_push_promise(self, path: str) -> None:
239         if "http.response.push" in self.scope.get("extensions", {}):
240             raw_headers = []
241             for name in SERVER_PUSH_HEADERS_TO_COPY:
242                 for value in self.headers.getlist(name):
243                     raw_headers.append(
244                         (name.encode("latin-1"), value.encode("latin-1"))
245                     )
246             await self._send(
247                 {"type": "http.response.push", "path": path, "headers": raw_headers}
248             )
249
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/starlette/requests.py b/starlette/requests.py
--- a/starlette/requests.py
+++ b/starlette/requests.py
@@ -91,7 +91,10 @@
             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

{"golden_diff": "diff --git a/starlette/requests.py b/starlette/requests.py\n--- a/starlette/requests.py\n+++ b/starlette/requests.py\n@@ -91,7 +91,10 @@\n             cookie_header = self.headers.get(\"cookie\")\n             if cookie_header:\n                 cookie = http.cookies.SimpleCookie()  # type: http.cookies.BaseCookie\n-                cookie.load(cookie_header)\n+                try:\n+                    cookie.load(cookie_header)\n+                except http.cookies.CookieError:\n+                    pass\n                 for key, morsel in cookie.items():\n                     cookies[key] = morsel.value\n             self._cookies = cookies\n", "issue": "[bug] Invalid cookie name leads to exception\nWhen handling a request with an invalid cookie name (does not conform to RFC2109) starlette raises an exception. i.e iam/cookiename\r\nThis is because Starlette uses Python's stdlib cookie library, which is very strict.\r\nI do understand the strictness, but in real life scenarios you receive such malformed cookies and I want to handle those requests.\r\nMy suggestion for a solution would be to catch those exceptions and ignore the invalid cookie. \r\n** EDIT **\r\nI just realized stdlib is used for the whole cookie header, hence can't ignore only one cookie.\r\nI'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?\n", "before_files": [{"content": "import asyncio\nimport http.cookies\nimport json\nimport typing\nfrom collections.abc import Mapping\n\nfrom starlette.datastructures import URL, Address, FormData, Headers, QueryParams, State\nfrom starlette.formparsers import FormParser, MultiPartParser\nfrom starlette.types import Message, Receive, Scope, Send\n\ntry:\n    from multipart.multipart import parse_options_header\nexcept ImportError:  # pragma: nocover\n    parse_options_header = None\n\n\nSERVER_PUSH_HEADERS_TO_COPY = {\n    \"accept\",\n    \"accept-encoding\",\n    \"accept-language\",\n    \"cache-control\",\n    \"user-agent\",\n}\n\n\nclass ClientDisconnect(Exception):\n    pass\n\n\nclass HTTPConnection(Mapping):\n    \"\"\"\n    A base class for incoming HTTP connections, that is used to provide\n    any functionality that is common to both `Request` and `WebSocket`.\n    \"\"\"\n\n    def __init__(self, scope: Scope, receive: Receive = None) -> None:\n        assert scope[\"type\"] in (\"http\", \"websocket\")\n        self.scope = scope\n\n    def __getitem__(self, key: str) -> str:\n        return self.scope[key]\n\n    def __iter__(self) -> typing.Iterator[str]:\n        return iter(self.scope)\n\n    def __len__(self) -> int:\n        return len(self.scope)\n\n    @property\n    def app(self) -> typing.Any:\n        return self.scope[\"app\"]\n\n    @property\n    def url(self) -> URL:\n        if not hasattr(self, \"_url\"):\n            self._url = URL(scope=self.scope)\n        return self._url\n\n    @property\n    def base_url(self) -> URL:\n        if not hasattr(self, \"_base_url\"):\n            base_url_scope = dict(self.scope)\n            base_url_scope[\"path\"] = \"/\"\n            base_url_scope[\"query_string\"] = b\"\"\n            base_url_scope[\"root_path\"] = base_url_scope.get(\n                \"app_root_path\", base_url_scope.get(\"root_path\", \"\")\n            )\n            self._base_url = URL(scope=base_url_scope)\n        return self._base_url\n\n    @property\n    def headers(self) -> Headers:\n        if not hasattr(self, \"_headers\"):\n            self._headers = Headers(scope=self.scope)\n        return self._headers\n\n    @property\n    def query_params(self) -> QueryParams:\n        if not hasattr(self, \"_query_params\"):\n            self._query_params = QueryParams(self.scope[\"query_string\"])\n        return self._query_params\n\n    @property\n    def path_params(self) -> dict:\n        return self.scope.get(\"path_params\", {})\n\n    @property\n    def cookies(self) -> typing.Dict[str, str]:\n        if not hasattr(self, \"_cookies\"):\n            cookies = {}\n            cookie_header = self.headers.get(\"cookie\")\n            if cookie_header:\n                cookie = http.cookies.SimpleCookie()  # type: http.cookies.BaseCookie\n                cookie.load(cookie_header)\n                for key, morsel in cookie.items():\n                    cookies[key] = morsel.value\n            self._cookies = cookies\n        return self._cookies\n\n    @property\n    def client(self) -> Address:\n        host, port = self.scope.get(\"client\") or (None, None)\n        return Address(host=host, port=port)\n\n    @property\n    def session(self) -> dict:\n        assert (\n            \"session\" in self.scope\n        ), \"SessionMiddleware must be installed to access request.session\"\n        return self.scope[\"session\"]\n\n    @property\n    def auth(self) -> typing.Any:\n        assert (\n            \"auth\" in self.scope\n        ), \"AuthenticationMiddleware must be installed to access request.auth\"\n        return self.scope[\"auth\"]\n\n    @property\n    def user(self) -> typing.Any:\n        assert (\n            \"user\" in self.scope\n        ), \"AuthenticationMiddleware must be installed to access request.user\"\n        return self.scope[\"user\"]\n\n    @property\n    def state(self) -> State:\n        if not hasattr(self, \"_state\"):\n            # Ensure 'state' has an empty dict if it's not already populated.\n            self.scope.setdefault(\"state\", {})\n            # Create a state instance with a reference to the dict in which it should store info\n            self._state = State(self.scope[\"state\"])\n        return self._state\n\n    def url_for(self, name: str, **path_params: typing.Any) -> str:\n        router = self.scope[\"router\"]\n        url_path = router.url_path_for(name, **path_params)\n        return url_path.make_absolute_url(base_url=self.base_url)\n\n\nasync def empty_receive() -> Message:\n    raise RuntimeError(\"Receive channel has not been made available\")\n\n\nasync def empty_send(message: Message) -> None:\n    raise RuntimeError(\"Send channel has not been made available\")\n\n\nclass Request(HTTPConnection):\n    def __init__(\n        self, scope: Scope, receive: Receive = empty_receive, send: Send = empty_send\n    ):\n        super().__init__(scope)\n        assert scope[\"type\"] == \"http\"\n        self._receive = receive\n        self._send = send\n        self._stream_consumed = False\n        self._is_disconnected = False\n\n    @property\n    def method(self) -> str:\n        return self.scope[\"method\"]\n\n    @property\n    def receive(self) -> Receive:\n        return self._receive\n\n    async def stream(self) -> typing.AsyncGenerator[bytes, None]:\n        if hasattr(self, \"_body\"):\n            yield self._body\n            yield b\"\"\n            return\n\n        if self._stream_consumed:\n            raise RuntimeError(\"Stream consumed\")\n\n        self._stream_consumed = True\n        while True:\n            message = await self._receive()\n            if message[\"type\"] == \"http.request\":\n                body = message.get(\"body\", b\"\")\n                if body:\n                    yield body\n                if not message.get(\"more_body\", False):\n                    break\n            elif message[\"type\"] == \"http.disconnect\":\n                self._is_disconnected = True\n                raise ClientDisconnect()\n        yield b\"\"\n\n    async def body(self) -> bytes:\n        if not hasattr(self, \"_body\"):\n            chunks = []\n            async for chunk in self.stream():\n                chunks.append(chunk)\n            self._body = b\"\".join(chunks)\n        return self._body\n\n    async def json(self) -> typing.Any:\n        if not hasattr(self, \"_json\"):\n            body = await self.body()\n            self._json = json.loads(body)\n        return self._json\n\n    async def form(self) -> FormData:\n        if not hasattr(self, \"_form\"):\n            assert (\n                parse_options_header is not None\n            ), \"The `python-multipart` library must be installed to use form parsing.\"\n            content_type_header = self.headers.get(\"Content-Type\")\n            content_type, options = parse_options_header(content_type_header)\n            if content_type == b\"multipart/form-data\":\n                multipart_parser = MultiPartParser(self.headers, self.stream())\n                self._form = await multipart_parser.parse()\n            elif content_type == b\"application/x-www-form-urlencoded\":\n                form_parser = FormParser(self.headers, self.stream())\n                self._form = await form_parser.parse()\n            else:\n                self._form = FormData()\n        return self._form\n\n    async def close(self) -> None:\n        if hasattr(self, \"_form\"):\n            await self._form.close()\n\n    async def is_disconnected(self) -> bool:\n        if not self._is_disconnected:\n            try:\n                message = await asyncio.wait_for(self._receive(), timeout=0.0000001)\n            except asyncio.TimeoutError:\n                message = {}\n\n            if message.get(\"type\") == \"http.disconnect\":\n                self._is_disconnected = True\n\n        return self._is_disconnected\n\n    async def send_push_promise(self, path: str) -> None:\n        if \"http.response.push\" in self.scope.get(\"extensions\", {}):\n            raw_headers = []\n            for name in SERVER_PUSH_HEADERS_TO_COPY:\n                for value in self.headers.getlist(name):\n                    raw_headers.append(\n                        (name.encode(\"latin-1\"), value.encode(\"latin-1\"))\n                    )\n            await self._send(\n                {\"type\": \"http.response.push\", \"path\": path, \"headers\": raw_headers}\n            )\n", "path": "starlette/requests.py"}], "after_files": [{"content": "import asyncio\nimport http.cookies\nimport json\nimport typing\nfrom collections.abc import Mapping\n\nfrom starlette.datastructures import URL, Address, FormData, Headers, QueryParams, State\nfrom starlette.formparsers import FormParser, MultiPartParser\nfrom starlette.types import Message, Receive, Scope, Send\n\ntry:\n    from multipart.multipart import parse_options_header\nexcept ImportError:  # pragma: nocover\n    parse_options_header = None\n\n\nSERVER_PUSH_HEADERS_TO_COPY = {\n    \"accept\",\n    \"accept-encoding\",\n    \"accept-language\",\n    \"cache-control\",\n    \"user-agent\",\n}\n\n\nclass ClientDisconnect(Exception):\n    pass\n\n\nclass HTTPConnection(Mapping):\n    \"\"\"\n    A base class for incoming HTTP connections, that is used to provide\n    any functionality that is common to both `Request` and `WebSocket`.\n    \"\"\"\n\n    def __init__(self, scope: Scope, receive: Receive = None) -> None:\n        assert scope[\"type\"] in (\"http\", \"websocket\")\n        self.scope = scope\n\n    def __getitem__(self, key: str) -> str:\n        return self.scope[key]\n\n    def __iter__(self) -> typing.Iterator[str]:\n        return iter(self.scope)\n\n    def __len__(self) -> int:\n        return len(self.scope)\n\n    @property\n    def app(self) -> typing.Any:\n        return self.scope[\"app\"]\n\n    @property\n    def url(self) -> URL:\n        if not hasattr(self, \"_url\"):\n            self._url = URL(scope=self.scope)\n        return self._url\n\n    @property\n    def base_url(self) -> URL:\n        if not hasattr(self, \"_base_url\"):\n            base_url_scope = dict(self.scope)\n            base_url_scope[\"path\"] = \"/\"\n            base_url_scope[\"query_string\"] = b\"\"\n            base_url_scope[\"root_path\"] = base_url_scope.get(\n                \"app_root_path\", base_url_scope.get(\"root_path\", \"\")\n            )\n            self._base_url = URL(scope=base_url_scope)\n        return self._base_url\n\n    @property\n    def headers(self) -> Headers:\n        if not hasattr(self, \"_headers\"):\n            self._headers = Headers(scope=self.scope)\n        return self._headers\n\n    @property\n    def query_params(self) -> QueryParams:\n        if not hasattr(self, \"_query_params\"):\n            self._query_params = QueryParams(self.scope[\"query_string\"])\n        return self._query_params\n\n    @property\n    def path_params(self) -> dict:\n        return self.scope.get(\"path_params\", {})\n\n    @property\n    def cookies(self) -> typing.Dict[str, str]:\n        if not hasattr(self, \"_cookies\"):\n            cookies = {}\n            cookie_header = self.headers.get(\"cookie\")\n            if cookie_header:\n                cookie = http.cookies.SimpleCookie()  # type: http.cookies.BaseCookie\n                try:\n                    cookie.load(cookie_header)\n                except http.cookies.CookieError:\n                    pass\n                for key, morsel in cookie.items():\n                    cookies[key] = morsel.value\n            self._cookies = cookies\n        return self._cookies\n\n    @property\n    def client(self) -> Address:\n        host, port = self.scope.get(\"client\") or (None, None)\n        return Address(host=host, port=port)\n\n    @property\n    def session(self) -> dict:\n        assert (\n            \"session\" in self.scope\n        ), \"SessionMiddleware must be installed to access request.session\"\n        return self.scope[\"session\"]\n\n    @property\n    def auth(self) -> typing.Any:\n        assert (\n            \"auth\" in self.scope\n        ), \"AuthenticationMiddleware must be installed to access request.auth\"\n        return self.scope[\"auth\"]\n\n    @property\n    def user(self) -> typing.Any:\n        assert (\n            \"user\" in self.scope\n        ), \"AuthenticationMiddleware must be installed to access request.user\"\n        return self.scope[\"user\"]\n\n    @property\n    def state(self) -> State:\n        if not hasattr(self, \"_state\"):\n            # Ensure 'state' has an empty dict if it's not already populated.\n            self.scope.setdefault(\"state\", {})\n            # Create a state instance with a reference to the dict in which it should store info\n            self._state = State(self.scope[\"state\"])\n        return self._state\n\n    def url_for(self, name: str, **path_params: typing.Any) -> str:\n        router = self.scope[\"router\"]\n        url_path = router.url_path_for(name, **path_params)\n        return url_path.make_absolute_url(base_url=self.base_url)\n\n\nasync def empty_receive() -> Message:\n    raise RuntimeError(\"Receive channel has not been made available\")\n\n\nasync def empty_send(message: Message) -> None:\n    raise RuntimeError(\"Send channel has not been made available\")\n\n\nclass Request(HTTPConnection):\n    def __init__(\n        self, scope: Scope, receive: Receive = empty_receive, send: Send = empty_send\n    ):\n        super().__init__(scope)\n        assert scope[\"type\"] == \"http\"\n        self._receive = receive\n        self._send = send\n        self._stream_consumed = False\n        self._is_disconnected = False\n\n    @property\n    def method(self) -> str:\n        return self.scope[\"method\"]\n\n    @property\n    def receive(self) -> Receive:\n        return self._receive\n\n    async def stream(self) -> typing.AsyncGenerator[bytes, None]:\n        if hasattr(self, \"_body\"):\n            yield self._body\n            yield b\"\"\n            return\n\n        if self._stream_consumed:\n            raise RuntimeError(\"Stream consumed\")\n\n        self._stream_consumed = True\n        while True:\n            message = await self._receive()\n            if message[\"type\"] == \"http.request\":\n                body = message.get(\"body\", b\"\")\n                if body:\n                    yield body\n                if not message.get(\"more_body\", False):\n                    break\n            elif message[\"type\"] == \"http.disconnect\":\n                self._is_disconnected = True\n                raise ClientDisconnect()\n        yield b\"\"\n\n    async def body(self) -> bytes:\n        if not hasattr(self, \"_body\"):\n            chunks = []\n            async for chunk in self.stream():\n                chunks.append(chunk)\n            self._body = b\"\".join(chunks)\n        return self._body\n\n    async def json(self) -> typing.Any:\n        if not hasattr(self, \"_json\"):\n            body = await self.body()\n            self._json = json.loads(body)\n        return self._json\n\n    async def form(self) -> FormData:\n        if not hasattr(self, \"_form\"):\n            assert (\n                parse_options_header is not None\n            ), \"The `python-multipart` library must be installed to use form parsing.\"\n            content_type_header = self.headers.get(\"Content-Type\")\n            content_type, options = parse_options_header(content_type_header)\n            if content_type == b\"multipart/form-data\":\n                multipart_parser = MultiPartParser(self.headers, self.stream())\n                self._form = await multipart_parser.parse()\n            elif content_type == b\"application/x-www-form-urlencoded\":\n                form_parser = FormParser(self.headers, self.stream())\n                self._form = await form_parser.parse()\n            else:\n                self._form = FormData()\n        return self._form\n\n    async def close(self) -> None:\n        if hasattr(self, \"_form\"):\n            await self._form.close()\n\n    async def is_disconnected(self) -> bool:\n        if not self._is_disconnected:\n            try:\n                message = await asyncio.wait_for(self._receive(), timeout=0.0000001)\n            except asyncio.TimeoutError:\n                message = {}\n\n            if message.get(\"type\") == \"http.disconnect\":\n                self._is_disconnected = True\n\n        return self._is_disconnected\n\n    async def send_push_promise(self, path: str) -> None:\n        if \"http.response.push\" in self.scope.get(\"extensions\", {}):\n            raw_headers = []\n            for name in SERVER_PUSH_HEADERS_TO_COPY:\n                for value in self.headers.getlist(name):\n                    raw_headers.append(\n                        (name.encode(\"latin-1\"), value.encode(\"latin-1\"))\n                    )\n            await self._send(\n                {\"type\": \"http.response.push\", \"path\": path, \"headers\": raw_headers}\n            )\n", "path": "starlette/requests.py"}]}