mirror of
https://github.com/element-hq/synapse.git
synced 2025-03-05 15:37:02 +00:00
feat: support for setting UA for URL previews
This commit is contained in:
parent
cee9da0da5
commit
5d24654812
3 changed files with 20 additions and 3 deletions
|
@ -774,6 +774,17 @@ Example configuration:
|
|||
```yaml
|
||||
max_event_delay_duration: 24h
|
||||
```
|
||||
---
|
||||
### `url_preview_user_agent`
|
||||
|
||||
Setting the User-Agent for URL previews.
|
||||
|
||||
Defaults to `Synapse (bot; +https://github.com/matrix-org/synapse)`.
|
||||
|
||||
Example configuration:
|
||||
```yaml
|
||||
url_preview_user_agent: "Hello Matrix"
|
||||
```
|
||||
|
||||
## Homeserver blocking
|
||||
Useful options for Synapse admins.
|
||||
|
|
|
@ -788,6 +788,13 @@ class ServerConfig(Config):
|
|||
else:
|
||||
self.max_event_delay_ms = None
|
||||
|
||||
self.url_preview_user_agent: str = (
|
||||
config.get("url_preview_user_agent")
|
||||
or "Synapse (bot; +https://github.com/matrix-org/synapse)"
|
||||
)
|
||||
if len(self.url_preview_user_agent.strip()) == 0:
|
||||
raise ConfigError("The 'url_preview_user_agent' must be a valid User-Agent")
|
||||
|
||||
def has_tls_listener(self) -> bool:
|
||||
return any(listener.is_tls() for listener in self.listeners)
|
||||
|
||||
|
|
|
@ -168,6 +168,7 @@ class UrlPreviewer:
|
|||
):
|
||||
self.clock = hs.get_clock()
|
||||
self.filepaths = media_repo.filepaths
|
||||
self.hs = hs
|
||||
self.max_spider_size = hs.config.media.max_spider_size
|
||||
self.server_name = hs.hostname
|
||||
self.store = hs.get_datastores().main
|
||||
|
@ -464,9 +465,7 @@ class UrlPreviewer:
|
|||
# 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)"
|
||||
],
|
||||
b"User-Agent": [self.hs.config.server.url_preview_user_agent],
|
||||
},
|
||||
is_allowed_content_type=_is_previewable,
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue