Sets a new string as response. The value must be a string or bytes. If a string is set it's encoded to the charset of the response (utf-8 by default). .. versionadded:: 0.9
(self, value: bytes | str)
| 287 | return rv |
| 288 | |
| 289 | def set_data(self, value: bytes | str) -> None: |
| 290 | """Sets a new string as response. The value must be a string or |
| 291 | bytes. If a string is set it's encoded to the charset of the |
| 292 | response (utf-8 by default). |
| 293 | |
| 294 | .. versionadded:: 0.9 |
| 295 | """ |
| 296 | if isinstance(value, str): |
| 297 | value = value.encode() |
| 298 | self.response = [value] |
| 299 | if self.automatically_set_content_length: |
| 300 | self.headers["Content-Length"] = str(len(value)) |
| 301 | |
| 302 | data = property( |
| 303 | get_data, |
no outgoing calls