diff --git a/synapse/http/client.py b/synapse/http/client.py index 49a2f3fb39ed..abe827a85cf4 100644 --- a/synapse/http/client.py +++ b/synapse/http/client.py @@ -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: @@ -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, ( diff --git a/synapse/rest/media/v1/preview_url_resource.py b/synapse/rest/media/v1/preview_url_resource.py index 9dd7425929f6..8d3d1e54dc9f 100644 --- a/synapse/rest/media/v1/preview_url_resource.py +++ b/synapse/rest/media/v1/preview_url_resource.py @@ -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)