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

Commit

Permalink
Fetch images when previewing Twitter URLs. (#11985)
Browse files Browse the repository at this point in the history
By including "bot" in the User-Agent, which some sites use
to decide whether to include additional Open Graph information.
  • Loading branch information
AndrewRyanChama authored Feb 22, 2022
1 parent 79c18e0 commit 0661716
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/11985.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fetch images when previewing Twitter URLs. Contributed by @AndrewRyanChama.
4 changes: 1 addition & 3 deletions synapse/res/providers.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
"endpoints": [
{
"schemes": [
"https://twitter.com/*/status/*",
"https://*.twitter.com/*/status/*",
"https://twitter.com/*/moments/*",
"https://*.twitter.com/*/moments/*"
],
"url": "https://publish.twitter.com/oembed"
}
]
}
]
]
10 changes: 9 additions & 1 deletion synapse/rest/media/v1/preview_url_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,15 @@ async def _download_url(self, url: str, output_stream: BinaryIO) -> DownloadResu
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:
Expand Down

0 comments on commit 0661716

Please sign in to comment.