Similar to `Message.content`, but does not raise if `strict` is `False`. Instead, the compressed message body is returned as-is.
(self, strict: bool = True)
| 383 | self.headers["content-length"] = str(len(self.raw_content)) |
| 384 | |
| 385 | def get_content(self, strict: bool = True) -> bytes | None: |
| 386 | """ |
| 387 | Similar to `Message.content`, but does not raise if `strict` is `False`. |
| 388 | Instead, the compressed message body is returned as-is. |
| 389 | """ |
| 390 | if self.raw_content is None: |
| 391 | return None |
| 392 | ce = self.headers.get("content-encoding") |
| 393 | if ce: |
| 394 | try: |
| 395 | content = encoding.decode(self.raw_content, ce) |
| 396 | # A client may illegally specify a byte -> str encoding here (e.g. utf8) |
| 397 | if isinstance(content, str): |
| 398 | raise ValueError(f"Invalid Content-Encoding: {ce}") |
| 399 | return content |
| 400 | except ValueError: |
| 401 | if strict: |
| 402 | raise |
| 403 | return self.raw_content |
| 404 | else: |
| 405 | return self.raw_content |
| 406 | |
| 407 | def set_text(self, text: str | None) -> None: |
| 408 | if text is None: |