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

Commit 915cd6a

Browse files
Use bot user agent for openGraph queries
We found that some websites return opengraph information based on the user agent. In order to address this, using (bot) in the user agent string may help the website behave correctly. When testing Twitter, we found that the correct metadata is returned with the (bot) user agent while it isn't for the default user agent. This change additionally updates providers.json, as with the user agent fix twitter will now return the expected openGraph metadata. Signed-off-by: Andrew Ryan <[email protected]>
1 parent 55113dd commit 915cd6a

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

changelog.d/11985.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use bot user agent for openGraph queries.

synapse/res/providers.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
"endpoints": [
66
{
77
"schemes": [
8-
"https://twitter.com/*/status/*",
9-
"https://*.twitter.com/*/status/*",
108
"https://twitter.com/*/moments/*",
119
"https://*.twitter.com/*/moments/*"
1210
],
1311
"url": "https://publish.twitter.com/oembed"
1412
}
1513
]
1614
}
17-
]
15+
]

synapse/rest/media/v1/preview_url_resource.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,12 @@ async def _download_url(self, url: str, output_stream: BinaryIO) -> DownloadResu
402402
url,
403403
output_stream=output_stream,
404404
max_size=self.max_spider_size,
405-
headers={"Accept-Language": self.url_preview_accept_language},
405+
headers={
406+
b"Accept-Language": self.url_preview_accept_language,
407+
b"User-Agent": [
408+
"Synapse (bot; +https://github.com/matrix-org/synapse)"
409+
],
410+
},
406411
is_allowed_content_type=_is_previewable,
407412
)
408413
except SynapseError:

0 commit comments

Comments
 (0)