Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Reuse existing content type helpers.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkasak committed Feb 10, 2022
1 parent 2f3bb1f commit 4376a70
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions synapse/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ async def get_file(
output_stream: BinaryIO,
max_size: Optional[int] = None,
headers: Optional[RawHeaders] = None,
is_allowed_content_type: Optional[Callable[[bytes], bool]] = None,
is_allowed_content_type: Optional[Callable[[str], bool]] = None,
) -> Tuple[int, Dict[bytes, List[bytes]], str, int]:
"""GETs a file from a given URL
Args:
Expand Down Expand Up @@ -735,7 +735,7 @@ async def get_file(

if is_allowed_content_type and b"Content-Type" in resp_headers:
content_type = resp_headers[b"Content-Type"][0]
if not is_allowed_content_type(content_type):
if not is_allowed_content_type(content_type.decode("ascii")):
raise SynapseError(
HTTPStatus.BAD_GATEWAY,
(
Expand Down
10 changes: 2 additions & 8 deletions synapse/rest/media/v1/preview_url_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,14 +764,8 @@ def _is_json(content_type: str) -> bool:
return content_type.lower().startswith("application/json")


def _is_previewable(content_type: bytes) -> bool:
def _is_previewable(content_type: str) -> bool:
"""Returns True for content types for which we will perform URL preview and False
otherwise."""

content_type = content_type.lower()
return (
content_type.startswith(b"text/html")
or content_type.startswith(b"application/xhtml")
or content_type.startswith(b"image/")
or content_type.startswith(b"application/json")
)
return _is_html(content_type) or _is_media(content_type) or _is_json(content_type)

0 comments on commit 4376a70

Please sign in to comment.