diff options
author | AndrewRyanChama <89478935+AndrewRyanChama@users.noreply.github.com> | 2022-02-22 04:11:39 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-22 07:11:39 -0500 |
commit | 066171643b5812b05dd9352ee650f524567de877 (patch) | |
tree | 8ad178c43f79808b359c640690394332c5a0676b /synapse/rest/media | |
parent | Merge remote-tracking branch 'origin/master' into develop (diff) | |
download | synapse-066171643b5812b05dd9352ee650f524567de877.tar.xz |
Fetch images when previewing Twitter URLs. (#11985)
By including "bot" in the User-Agent, which some sites use to decide whether to include additional Open Graph information.
Diffstat (limited to 'synapse/rest/media')
-rw-r--r-- | synapse/rest/media/v1/preview_url_resource.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/synapse/rest/media/v1/preview_url_resource.py b/synapse/rest/media/v1/preview_url_resource.py index 8d3d1e54dc..c08b60d10a 100644 --- a/synapse/rest/media/v1/preview_url_resource.py +++ b/synapse/rest/media/v1/preview_url_resource.py @@ -402,7 +402,15 @@ class PreviewUrlResource(DirectServeJsonResource): url, output_stream=output_stream, max_size=self.max_spider_size, - headers={"Accept-Language": self.url_preview_accept_language}, + headers={ + b"Accept-Language": self.url_preview_accept_language, + # Use a custom user agent for the preview because some sites will only return + # Open Graph metadata to crawler user agents. Omit the Synapse version + # string to avoid leaking information. + b"User-Agent": [ + "Synapse (bot; +https://github.com/matrix-org/synapse)" + ], + }, is_allowed_content_type=_is_previewable, ) except SynapseError: |