Fix URL previewer user agent to fix Twitter previews

This commit is contained in:
Tulir Asokan 2020-11-18 01:21:48 +02:00
parent c4710fb8cf
commit 55d926999c
2 changed files with 3 additions and 13 deletions

View file

@ -232,6 +232,7 @@ class SimpleHttpClient:
ip_blacklist=None,
http_proxy=None,
https_proxy=None,
user_agent=None,
):
"""
Args:
@ -250,7 +251,7 @@ class SimpleHttpClient:
self._ip_blacklist = ip_blacklist
self._extra_treq_args = treq_args
self.user_agent = hs.version_string
self.user_agent = user_agent or hs.version_string
self.clock = hs.get_clock()
if hs.config.user_agent_suffix:
self.user_agent = "%s %s" % (self.user_agent, hs.config.user_agent_suffix)

View file

@ -60,18 +60,6 @@ ONE_HOUR = 60 * 60 * 1000
# A map of globs to API endpoints.
_oembed_globs = {
# Twitter.
"https://publish.twitter.com/oembed": [
"https://twitter.com/*/status/*",
"https://*.twitter.com/*/status/*",
"https://twitter.com/*/moments/*",
"https://*.twitter.com/*/moments/*",
# Include the HTTP versions too.
"http://twitter.com/*/status/*",
"http://*.twitter.com/*/status/*",
"http://twitter.com/*/moments/*",
"http://*.twitter.com/*/moments/*",
],
}
# Convert the globs to regular expressions.
_oembed_patterns = {}
@ -135,6 +123,7 @@ class PreviewUrlResource(DirectServeJsonResource):
ip_blacklist=hs.config.url_preview_ip_range_blacklist,
http_proxy=os.getenvb(b"http_proxy"),
https_proxy=os.getenvb(b"HTTPS_PROXY"),
user_agent=f"{hs.version_string} UrlPreviewBot"
)
self.media_repo = media_repo
self.primary_base_path = media_repo.primary_base_path