We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Response's content default to b''
close https://github.com/encode/starlette/issues/201

--- 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/responses.py`
Content:
```
1 import hashlib
2 import http.cookies
3 import json
4 import os
5 import stat
6 import typing
7 from email.utils import formatdate
8 from mimetypes import guess_type
9 from urllib.parse import quote_plus
10 
11 from starlette.background import BackgroundTask
12 from starlette.datastructures import URL, MutableHeaders
13 from starlette.types import Receive, Send
14 
15 try:
16     import aiofiles
17     from aiofiles.os import stat as aio_stat
18 except ImportError:  # pragma: nocover
19     aiofiles = None  # type: ignore
20     aio_stat = None  # type: ignore
21 
22 try:
23     import ujson
24 except ImportError:  # pragma: nocover
25     ujson = None  # type: ignore
26 
27 
28 class Response:
29     media_type = None
30     charset = "utf-8"
31 
32     def __init__(
33         self,
34         content: typing.Any,
35         status_code: int = 200,
36         headers: dict = None,
37         media_type: str = None,
38         background: BackgroundTask = None,
39     ) -> None:
40         self.body = self.render(content)
41         self.status_code = status_code
42         if media_type is not None:
43             self.media_type = media_type
44         self.background = background
45         self.init_headers(headers)
46 
47     def render(self, content: typing.Any) -> bytes:
48         if isinstance(content, bytes):
49             return content
50         return content.encode(self.charset)
51 
52     def init_headers(self, headers: typing.Mapping[str, str] = None) -> None:
53         if headers is None:
54             raw_headers = []  # type: typing.List[typing.Tuple[bytes, bytes]]
55             populate_content_length = True
56             populate_content_type = True
57         else:
58             raw_headers = [
59                 (k.lower().encode("latin-1"), v.encode("latin-1"))
60                 for k, v in headers.items()
61             ]
62             keys = [h[0] for h in raw_headers]
63             populate_content_length = b"content-length" in keys
64             populate_content_type = b"content-type" in keys
65 
66         body = getattr(self, "body", None)
67         if body is not None and populate_content_length:
68             content_length = str(len(body))
69             raw_headers.append((b"content-length", content_length.encode("latin-1")))
70 
71         content_type = self.media_type
72         if content_type is not None and populate_content_type:
73             if content_type.startswith("text/"):
74                 content_type += "; charset=" + self.charset
75             raw_headers.append((b"content-type", content_type.encode("latin-1")))
76 
77         self.raw_headers = raw_headers
78 
79     @property
80     def headers(self) -> MutableHeaders:
81         if not hasattr(self, "_headers"):
82             self._headers = MutableHeaders(raw=self.raw_headers)
83         return self._headers
84 
85     def set_cookie(
86         self,
87         key: str,
88         value: str = "",
89         max_age: int = None,
90         expires: int = None,
91         path: str = "/",
92         domain: str = None,
93         secure: bool = False,
94         httponly: bool = False,
95     ) -> None:
96         cookie = http.cookies.SimpleCookie()
97         cookie[key] = value
98         if max_age is not None:
99             cookie[key]["max-age"] = max_age  # type: ignore
100         if expires is not None:
101             cookie[key]["expires"] = expires  # type: ignore
102         if path is not None:
103             cookie[key]["path"] = path
104         if domain is not None:
105             cookie[key]["domain"] = domain
106         if secure:
107             cookie[key]["secure"] = True  # type: ignore
108         if httponly:
109             cookie[key]["httponly"] = True  # type: ignore
110         cookie_val = cookie.output(header="").strip()
111         self.raw_headers.append((b"set-cookie", cookie_val.encode("latin-1")))
112 
113     def delete_cookie(self, key: str, path: str = "/", domain: str = None) -> None:
114         self.set_cookie(key, expires=0, max_age=0, path=path, domain=domain)
115 
116     async def __call__(self, receive: Receive, send: Send) -> None:
117         await send(
118             {
119                 "type": "http.response.start",
120                 "status": self.status_code,
121                 "headers": self.raw_headers,
122             }
123         )
124         await send({"type": "http.response.body", "body": self.body})
125 
126         if self.background is not None:
127             await self.background()
128 
129 
130 class HTMLResponse(Response):
131     media_type = "text/html"
132 
133 
134 class PlainTextResponse(Response):
135     media_type = "text/plain"
136 
137 
138 class JSONResponse(Response):
139     media_type = "application/json"
140 
141     def render(self, content: typing.Any) -> bytes:
142         return json.dumps(
143             content,
144             ensure_ascii=False,
145             allow_nan=False,
146             indent=None,
147             separators=(",", ":"),
148         ).encode("utf-8")
149 
150 
151 class UJSONResponse(JSONResponse):
152     media_type = "application/json"
153 
154     def render(self, content: typing.Any) -> bytes:
155         return ujson.dumps(content, ensure_ascii=False).encode("utf-8")
156 
157 
158 class RedirectResponse(Response):
159     def __init__(
160         self, url: typing.Union[str, URL], status_code: int = 302, headers: dict = None
161     ) -> None:
162         super().__init__(content=b"", status_code=status_code, headers=headers)
163         self.headers["location"] = quote_plus(str(url), safe=":/#?&=@[]!$&'()*+,;")
164 
165 
166 class StreamingResponse(Response):
167     def __init__(
168         self,
169         content: typing.Any,
170         status_code: int = 200,
171         headers: dict = None,
172         media_type: str = None,
173         background: BackgroundTask = None,
174     ) -> None:
175         self.body_iterator = content
176         self.status_code = status_code
177         self.media_type = self.media_type if media_type is None else media_type
178         self.background = background
179         self.init_headers(headers)
180 
181     async def __call__(self, receive: Receive, send: Send) -> None:
182         await send(
183             {
184                 "type": "http.response.start",
185                 "status": self.status_code,
186                 "headers": self.raw_headers,
187             }
188         )
189         async for chunk in self.body_iterator:
190             if not isinstance(chunk, bytes):
191                 chunk = chunk.encode(self.charset)
192             await send({"type": "http.response.body", "body": chunk, "more_body": True})
193         await send({"type": "http.response.body", "body": b"", "more_body": False})
194 
195         if self.background is not None:
196             await self.background()
197 
198 
199 class FileResponse(Response):
200     chunk_size = 4096
201 
202     def __init__(
203         self,
204         path: str,
205         headers: dict = None,
206         media_type: str = None,
207         background: BackgroundTask = None,
208         filename: str = None,
209         stat_result: os.stat_result = None,
210         method: str = None,
211     ) -> None:
212         assert aiofiles is not None, "'aiofiles' must be installed to use FileResponse"
213         self.path = path
214         self.status_code = 200
215         self.filename = filename
216         self.send_header_only = method is not None and method.upper() == "HEAD"
217         if media_type is None:
218             media_type = guess_type(filename or path)[0] or "text/plain"
219         self.media_type = media_type
220         self.background = background
221         self.init_headers(headers)
222         if self.filename is not None:
223             content_disposition = 'attachment; filename="{}"'.format(self.filename)
224             self.headers.setdefault("content-disposition", content_disposition)
225         self.stat_result = stat_result
226         if stat_result is not None:
227             self.set_stat_headers(stat_result)
228 
229     def set_stat_headers(self, stat_result: os.stat_result) -> None:
230         content_length = str(stat_result.st_size)
231         last_modified = formatdate(stat_result.st_mtime, usegmt=True)
232         etag_base = str(stat_result.st_mtime) + "-" + str(stat_result.st_size)
233         etag = hashlib.md5(etag_base.encode()).hexdigest()
234         self.headers.setdefault("content-length", content_length)
235         self.headers.setdefault("last-modified", last_modified)
236         self.headers.setdefault("etag", etag)
237 
238     async def __call__(self, receive: Receive, send: Send) -> None:
239         if self.stat_result is None:
240             try:
241                 stat_result = await aio_stat(self.path)
242                 self.set_stat_headers(stat_result)
243             except FileNotFoundError:
244                 raise RuntimeError(f"File at path {self.path} does not exist.")
245             else:
246                 mode = stat_result.st_mode
247                 if not stat.S_ISREG(mode):
248                     raise RuntimeError(f"File at path {self.path} is not a file.")
249         await send(
250             {
251                 "type": "http.response.start",
252                 "status": self.status_code,
253                 "headers": self.raw_headers,
254             }
255         )
256         if self.send_header_only:
257             await send({"type": "http.response.body"})
258         else:
259             async with aiofiles.open(self.path, mode="rb") as file:
260                 more_body = True
261                 while more_body:
262                     chunk = await file.read(self.chunk_size)
263                     more_body = len(chunk) == self.chunk_size
264                     await send(
265                         {
266                             "type": "http.response.body",
267                             "body": chunk,
268                             "more_body": more_body,
269                         }
270                     )
271         if self.background is not None:
272             await self.background()
273
```
--- 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/responses.py b/starlette/responses.py
--- a/starlette/responses.py
+++ b/starlette/responses.py
@@ -31,13 +31,16 @@
 
     def __init__(
         self,
-        content: typing.Any,
+        content: typing.Any = None,
         status_code: int = 200,
         headers: dict = None,
         media_type: str = None,
         background: BackgroundTask = None,
     ) -> None:
-        self.body = self.render(content)
+        if content is None:
+            self.body = b""
+        else:
+            self.body = self.render(content)
         self.status_code = status_code
         if media_type is not None:
             self.media_type = media_type
@@ -63,8 +66,8 @@
             populate_content_length = b"content-length" in keys
             populate_content_type = b"content-type" in keys
 
-        body = getattr(self, "body", None)
-        if body is not None and populate_content_length:
+        body = getattr(self, "body", b"")
+        if body and populate_content_length:
             content_length = str(len(body))
             raw_headers.append((b"content-length", content_length.encode("latin-1")))

{"golden_diff": "diff --git a/starlette/responses.py b/starlette/responses.py\n--- a/starlette/responses.py\n+++ b/starlette/responses.py\n@@ -31,13 +31,16 @@\n \n     def __init__(\n         self,\n-        content: typing.Any,\n+        content: typing.Any = None,\n         status_code: int = 200,\n         headers: dict = None,\n         media_type: str = None,\n         background: BackgroundTask = None,\n     ) -> None:\n-        self.body = self.render(content)\n+        if content is None:\n+            self.body = b\"\"\n+        else:\n+            self.body = self.render(content)\n         self.status_code = status_code\n         if media_type is not None:\n             self.media_type = media_type\n@@ -63,8 +66,8 @@\n             populate_content_length = b\"content-length\" in keys\n             populate_content_type = b\"content-type\" in keys\n \n-        body = getattr(self, \"body\", None)\n-        if body is not None and populate_content_length:\n+        body = getattr(self, \"body\", b\"\")\n+        if body and populate_content_length:\n             content_length = str(len(body))\n             raw_headers.append((b\"content-length\", content_length.encode(\"latin-1\")))\n", "issue": "Response's content default to b''\nclose https://github.com/encode/starlette/issues/201\n", "before_files": [{"content": "import hashlib\nimport http.cookies\nimport json\nimport os\nimport stat\nimport typing\nfrom email.utils import formatdate\nfrom mimetypes import guess_type\nfrom urllib.parse import quote_plus\n\nfrom starlette.background import BackgroundTask\nfrom starlette.datastructures import URL, MutableHeaders\nfrom starlette.types import Receive, Send\n\ntry:\n    import aiofiles\n    from aiofiles.os import stat as aio_stat\nexcept ImportError:  # pragma: nocover\n    aiofiles = None  # type: ignore\n    aio_stat = None  # type: ignore\n\ntry:\n    import ujson\nexcept ImportError:  # pragma: nocover\n    ujson = None  # type: ignore\n\n\nclass Response:\n    media_type = None\n    charset = \"utf-8\"\n\n    def __init__(\n        self,\n        content: typing.Any,\n        status_code: int = 200,\n        headers: dict = None,\n        media_type: str = None,\n        background: BackgroundTask = None,\n    ) -> None:\n        self.body = self.render(content)\n        self.status_code = status_code\n        if media_type is not None:\n            self.media_type = media_type\n        self.background = background\n        self.init_headers(headers)\n\n    def render(self, content: typing.Any) -> bytes:\n        if isinstance(content, bytes):\n            return content\n        return content.encode(self.charset)\n\n    def init_headers(self, headers: typing.Mapping[str, str] = None) -> None:\n        if headers is None:\n            raw_headers = []  # type: typing.List[typing.Tuple[bytes, bytes]]\n            populate_content_length = True\n            populate_content_type = True\n        else:\n            raw_headers = [\n                (k.lower().encode(\"latin-1\"), v.encode(\"latin-1\"))\n                for k, v in headers.items()\n            ]\n            keys = [h[0] for h in raw_headers]\n            populate_content_length = b\"content-length\" in keys\n            populate_content_type = b\"content-type\" in keys\n\n        body = getattr(self, \"body\", None)\n        if body is not None and populate_content_length:\n            content_length = str(len(body))\n            raw_headers.append((b\"content-length\", content_length.encode(\"latin-1\")))\n\n        content_type = self.media_type\n        if content_type is not None and populate_content_type:\n            if content_type.startswith(\"text/\"):\n                content_type += \"; charset=\" + self.charset\n            raw_headers.append((b\"content-type\", content_type.encode(\"latin-1\")))\n\n        self.raw_headers = raw_headers\n\n    @property\n    def headers(self) -> MutableHeaders:\n        if not hasattr(self, \"_headers\"):\n            self._headers = MutableHeaders(raw=self.raw_headers)\n        return self._headers\n\n    def set_cookie(\n        self,\n        key: str,\n        value: str = \"\",\n        max_age: int = None,\n        expires: int = None,\n        path: str = \"/\",\n        domain: str = None,\n        secure: bool = False,\n        httponly: bool = False,\n    ) -> None:\n        cookie = http.cookies.SimpleCookie()\n        cookie[key] = value\n        if max_age is not None:\n            cookie[key][\"max-age\"] = max_age  # type: ignore\n        if expires is not None:\n            cookie[key][\"expires\"] = expires  # type: ignore\n        if path is not None:\n            cookie[key][\"path\"] = path\n        if domain is not None:\n            cookie[key][\"domain\"] = domain\n        if secure:\n            cookie[key][\"secure\"] = True  # type: ignore\n        if httponly:\n            cookie[key][\"httponly\"] = True  # type: ignore\n        cookie_val = cookie.output(header=\"\").strip()\n        self.raw_headers.append((b\"set-cookie\", cookie_val.encode(\"latin-1\")))\n\n    def delete_cookie(self, key: str, path: str = \"/\", domain: str = None) -> None:\n        self.set_cookie(key, expires=0, max_age=0, path=path, domain=domain)\n\n    async def __call__(self, receive: Receive, send: Send) -> None:\n        await send(\n            {\n                \"type\": \"http.response.start\",\n                \"status\": self.status_code,\n                \"headers\": self.raw_headers,\n            }\n        )\n        await send({\"type\": \"http.response.body\", \"body\": self.body})\n\n        if self.background is not None:\n            await self.background()\n\n\nclass HTMLResponse(Response):\n    media_type = \"text/html\"\n\n\nclass PlainTextResponse(Response):\n    media_type = \"text/plain\"\n\n\nclass JSONResponse(Response):\n    media_type = \"application/json\"\n\n    def render(self, content: typing.Any) -> bytes:\n        return json.dumps(\n            content,\n            ensure_ascii=False,\n            allow_nan=False,\n            indent=None,\n            separators=(\",\", \":\"),\n        ).encode(\"utf-8\")\n\n\nclass UJSONResponse(JSONResponse):\n    media_type = \"application/json\"\n\n    def render(self, content: typing.Any) -> bytes:\n        return ujson.dumps(content, ensure_ascii=False).encode(\"utf-8\")\n\n\nclass RedirectResponse(Response):\n    def __init__(\n        self, url: typing.Union[str, URL], status_code: int = 302, headers: dict = None\n    ) -> None:\n        super().__init__(content=b\"\", status_code=status_code, headers=headers)\n        self.headers[\"location\"] = quote_plus(str(url), safe=\":/#?&=@[]!$&'()*+,;\")\n\n\nclass StreamingResponse(Response):\n    def __init__(\n        self,\n        content: typing.Any,\n        status_code: int = 200,\n        headers: dict = None,\n        media_type: str = None,\n        background: BackgroundTask = None,\n    ) -> None:\n        self.body_iterator = content\n        self.status_code = status_code\n        self.media_type = self.media_type if media_type is None else media_type\n        self.background = background\n        self.init_headers(headers)\n\n    async def __call__(self, receive: Receive, send: Send) -> None:\n        await send(\n            {\n                \"type\": \"http.response.start\",\n                \"status\": self.status_code,\n                \"headers\": self.raw_headers,\n            }\n        )\n        async for chunk in self.body_iterator:\n            if not isinstance(chunk, bytes):\n                chunk = chunk.encode(self.charset)\n            await send({\"type\": \"http.response.body\", \"body\": chunk, \"more_body\": True})\n        await send({\"type\": \"http.response.body\", \"body\": b\"\", \"more_body\": False})\n\n        if self.background is not None:\n            await self.background()\n\n\nclass FileResponse(Response):\n    chunk_size = 4096\n\n    def __init__(\n        self,\n        path: str,\n        headers: dict = None,\n        media_type: str = None,\n        background: BackgroundTask = None,\n        filename: str = None,\n        stat_result: os.stat_result = None,\n        method: str = None,\n    ) -> None:\n        assert aiofiles is not None, \"'aiofiles' must be installed to use FileResponse\"\n        self.path = path\n        self.status_code = 200\n        self.filename = filename\n        self.send_header_only = method is not None and method.upper() == \"HEAD\"\n        if media_type is None:\n            media_type = guess_type(filename or path)[0] or \"text/plain\"\n        self.media_type = media_type\n        self.background = background\n        self.init_headers(headers)\n        if self.filename is not None:\n            content_disposition = 'attachment; filename=\"{}\"'.format(self.filename)\n            self.headers.setdefault(\"content-disposition\", content_disposition)\n        self.stat_result = stat_result\n        if stat_result is not None:\n            self.set_stat_headers(stat_result)\n\n    def set_stat_headers(self, stat_result: os.stat_result) -> None:\n        content_length = str(stat_result.st_size)\n        last_modified = formatdate(stat_result.st_mtime, usegmt=True)\n        etag_base = str(stat_result.st_mtime) + \"-\" + str(stat_result.st_size)\n        etag = hashlib.md5(etag_base.encode()).hexdigest()\n        self.headers.setdefault(\"content-length\", content_length)\n        self.headers.setdefault(\"last-modified\", last_modified)\n        self.headers.setdefault(\"etag\", etag)\n\n    async def __call__(self, receive: Receive, send: Send) -> None:\n        if self.stat_result is None:\n            try:\n                stat_result = await aio_stat(self.path)\n                self.set_stat_headers(stat_result)\n            except FileNotFoundError:\n                raise RuntimeError(f\"File at path {self.path} does not exist.\")\n            else:\n                mode = stat_result.st_mode\n                if not stat.S_ISREG(mode):\n                    raise RuntimeError(f\"File at path {self.path} is not a file.\")\n        await send(\n            {\n                \"type\": \"http.response.start\",\n                \"status\": self.status_code,\n                \"headers\": self.raw_headers,\n            }\n        )\n        if self.send_header_only:\n            await send({\"type\": \"http.response.body\"})\n        else:\n            async with aiofiles.open(self.path, mode=\"rb\") as file:\n                more_body = True\n                while more_body:\n                    chunk = await file.read(self.chunk_size)\n                    more_body = len(chunk) == self.chunk_size\n                    await send(\n                        {\n                            \"type\": \"http.response.body\",\n                            \"body\": chunk,\n                            \"more_body\": more_body,\n                        }\n                    )\n        if self.background is not None:\n            await self.background()\n", "path": "starlette/responses.py"}], "after_files": [{"content": "import hashlib\nimport http.cookies\nimport json\nimport os\nimport stat\nimport typing\nfrom email.utils import formatdate\nfrom mimetypes import guess_type\nfrom urllib.parse import quote_plus\n\nfrom starlette.background import BackgroundTask\nfrom starlette.datastructures import URL, MutableHeaders\nfrom starlette.types import Receive, Send\n\ntry:\n    import aiofiles\n    from aiofiles.os import stat as aio_stat\nexcept ImportError:  # pragma: nocover\n    aiofiles = None  # type: ignore\n    aio_stat = None  # type: ignore\n\ntry:\n    import ujson\nexcept ImportError:  # pragma: nocover\n    ujson = None  # type: ignore\n\n\nclass Response:\n    media_type = None\n    charset = \"utf-8\"\n\n    def __init__(\n        self,\n        content: typing.Any = None,\n        status_code: int = 200,\n        headers: dict = None,\n        media_type: str = None,\n        background: BackgroundTask = None,\n    ) -> None:\n        if content is None:\n            self.body = b\"\"\n        else:\n            self.body = self.render(content)\n        self.status_code = status_code\n        if media_type is not None:\n            self.media_type = media_type\n        self.background = background\n        self.init_headers(headers)\n\n    def render(self, content: typing.Any) -> bytes:\n        if isinstance(content, bytes):\n            return content\n        return content.encode(self.charset)\n\n    def init_headers(self, headers: typing.Mapping[str, str] = None) -> None:\n        if headers is None:\n            raw_headers = []  # type: typing.List[typing.Tuple[bytes, bytes]]\n            populate_content_length = True\n            populate_content_type = True\n        else:\n            raw_headers = [\n                (k.lower().encode(\"latin-1\"), v.encode(\"latin-1\"))\n                for k, v in headers.items()\n            ]\n            keys = [h[0] for h in raw_headers]\n            populate_content_length = b\"content-length\" in keys\n            populate_content_type = b\"content-type\" in keys\n\n        body = getattr(self, \"body\", b\"\")\n        if body and populate_content_length:\n            content_length = str(len(body))\n            raw_headers.append((b\"content-length\", content_length.encode(\"latin-1\")))\n\n        content_type = self.media_type\n        if content_type is not None and populate_content_type:\n            if content_type.startswith(\"text/\"):\n                content_type += \"; charset=\" + self.charset\n            raw_headers.append((b\"content-type\", content_type.encode(\"latin-1\")))\n\n        self.raw_headers = raw_headers\n\n    @property\n    def headers(self) -> MutableHeaders:\n        if not hasattr(self, \"_headers\"):\n            self._headers = MutableHeaders(raw=self.raw_headers)\n        return self._headers\n\n    def set_cookie(\n        self,\n        key: str,\n        value: str = \"\",\n        max_age: int = None,\n        expires: int = None,\n        path: str = \"/\",\n        domain: str = None,\n        secure: bool = False,\n        httponly: bool = False,\n    ) -> None:\n        cookie = http.cookies.SimpleCookie()\n        cookie[key] = value\n        if max_age is not None:\n            cookie[key][\"max-age\"] = max_age  # type: ignore\n        if expires is not None:\n            cookie[key][\"expires\"] = expires  # type: ignore\n        if path is not None:\n            cookie[key][\"path\"] = path\n        if domain is not None:\n            cookie[key][\"domain\"] = domain\n        if secure:\n            cookie[key][\"secure\"] = True  # type: ignore\n        if httponly:\n            cookie[key][\"httponly\"] = True  # type: ignore\n        cookie_val = cookie.output(header=\"\").strip()\n        self.raw_headers.append((b\"set-cookie\", cookie_val.encode(\"latin-1\")))\n\n    def delete_cookie(self, key: str, path: str = \"/\", domain: str = None) -> None:\n        self.set_cookie(key, expires=0, max_age=0, path=path, domain=domain)\n\n    async def __call__(self, receive: Receive, send: Send) -> None:\n        await send(\n            {\n                \"type\": \"http.response.start\",\n                \"status\": self.status_code,\n                \"headers\": self.raw_headers,\n            }\n        )\n        await send({\"type\": \"http.response.body\", \"body\": self.body})\n\n        if self.background is not None:\n            await self.background()\n\n\nclass HTMLResponse(Response):\n    media_type = \"text/html\"\n\n\nclass PlainTextResponse(Response):\n    media_type = \"text/plain\"\n\n\nclass JSONResponse(Response):\n    media_type = \"application/json\"\n\n    def render(self, content: typing.Any) -> bytes:\n        return json.dumps(\n            content,\n            ensure_ascii=False,\n            allow_nan=False,\n            indent=None,\n            separators=(\",\", \":\"),\n        ).encode(\"utf-8\")\n\n\nclass UJSONResponse(JSONResponse):\n    media_type = \"application/json\"\n\n    def render(self, content: typing.Any) -> bytes:\n        return ujson.dumps(content, ensure_ascii=False).encode(\"utf-8\")\n\n\nclass RedirectResponse(Response):\n    def __init__(\n        self, url: typing.Union[str, URL], status_code: int = 302, headers: dict = None\n    ) -> None:\n        super().__init__(content=b\"\", status_code=status_code, headers=headers)\n        self.headers[\"location\"] = quote_plus(str(url), safe=\":/#?&=@[]!$&'()*+,;\")\n\n\nclass StreamingResponse(Response):\n    def __init__(\n        self,\n        content: typing.Any,\n        status_code: int = 200,\n        headers: dict = None,\n        media_type: str = None,\n        background: BackgroundTask = None,\n    ) -> None:\n        self.body_iterator = content\n        self.status_code = status_code\n        self.media_type = self.media_type if media_type is None else media_type\n        self.background = background\n        self.init_headers(headers)\n\n    async def __call__(self, receive: Receive, send: Send) -> None:\n        await send(\n            {\n                \"type\": \"http.response.start\",\n                \"status\": self.status_code,\n                \"headers\": self.raw_headers,\n            }\n        )\n        async for chunk in self.body_iterator:\n            if not isinstance(chunk, bytes):\n                chunk = chunk.encode(self.charset)\n            await send({\"type\": \"http.response.body\", \"body\": chunk, \"more_body\": True})\n        await send({\"type\": \"http.response.body\", \"body\": b\"\", \"more_body\": False})\n\n        if self.background is not None:\n            await self.background()\n\n\nclass FileResponse(Response):\n    chunk_size = 4096\n\n    def __init__(\n        self,\n        path: str,\n        headers: dict = None,\n        media_type: str = None,\n        background: BackgroundTask = None,\n        filename: str = None,\n        stat_result: os.stat_result = None,\n        method: str = None,\n    ) -> None:\n        assert aiofiles is not None, \"'aiofiles' must be installed to use FileResponse\"\n        self.path = path\n        self.status_code = 200\n        self.filename = filename\n        self.send_header_only = method is not None and method.upper() == \"HEAD\"\n        if media_type is None:\n            media_type = guess_type(filename or path)[0] or \"text/plain\"\n        self.media_type = media_type\n        self.background = background\n        self.init_headers(headers)\n        if self.filename is not None:\n            content_disposition = 'attachment; filename=\"{}\"'.format(self.filename)\n            self.headers.setdefault(\"content-disposition\", content_disposition)\n        self.stat_result = stat_result\n        if stat_result is not None:\n            self.set_stat_headers(stat_result)\n\n    def set_stat_headers(self, stat_result: os.stat_result) -> None:\n        content_length = str(stat_result.st_size)\n        last_modified = formatdate(stat_result.st_mtime, usegmt=True)\n        etag_base = str(stat_result.st_mtime) + \"-\" + str(stat_result.st_size)\n        etag = hashlib.md5(etag_base.encode()).hexdigest()\n        self.headers.setdefault(\"content-length\", content_length)\n        self.headers.setdefault(\"last-modified\", last_modified)\n        self.headers.setdefault(\"etag\", etag)\n\n    async def __call__(self, receive: Receive, send: Send) -> None:\n        if self.stat_result is None:\n            try:\n                stat_result = await aio_stat(self.path)\n                self.set_stat_headers(stat_result)\n            except FileNotFoundError:\n                raise RuntimeError(f\"File at path {self.path} does not exist.\")\n            else:\n                mode = stat_result.st_mode\n                if not stat.S_ISREG(mode):\n                    raise RuntimeError(f\"File at path {self.path} is not a file.\")\n        await send(\n            {\n                \"type\": \"http.response.start\",\n                \"status\": self.status_code,\n                \"headers\": self.raw_headers,\n            }\n        )\n        if self.send_header_only:\n            await send({\"type\": \"http.response.body\"})\n        else:\n            async with aiofiles.open(self.path, mode=\"rb\") as file:\n                more_body = True\n                while more_body:\n                    chunk = await file.read(self.chunk_size)\n                    more_body = len(chunk) == self.chunk_size\n                    await send(\n                        {\n                            \"type\": \"http.response.body\",\n                            \"body\": chunk,\n                            \"more_body\": more_body,\n                        }\n                    )\n        if self.background is not None:\n            await self.background()\n", "path": "starlette/responses.py"}]}