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

Commit 0ef1307

Browse files
VetchuDMRobertson
andauthored
Add custom well-known (#13035)
Co-authored-by: David Robertson <[email protected]>
1 parent ffe2464 commit 0ef1307

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

changelog.d/13035.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow server admins to customise the response of the `/.well-known/matrix/client` endpoint.

docs/usage/configuration/config_documentation.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,22 @@ Example configuration:
230230
serve_server_wellknown: true
231231
```
232232
---
233+
### `extra_well_known_client_content `
234+
235+
This option allows server runners to add arbitrary key-value pairs to the [client-facing `.well-known` response](https://spec.matrix.org/latest/client-server-api/#well-known-uri).
236+
Note that the `public_baseurl` config option must be provided for Synapse to serve a response to `/.well-known/matrix/client` at all.
237+
238+
If this option is provided, it parses the given yaml to json and
239+
serves it on `/.well-known/matrix/client` endpoint
240+
alongside the standard properties.
241+
242+
Example configuration:
243+
```yaml
244+
extra_well_known_client_content :
245+
option1: value1
246+
option2: value2
247+
```
248+
---
233249
### `soft_file_limit`
234250

235251
Set the soft limit on the number of file descriptors synapse can use.
@@ -3580,3 +3596,4 @@ background_updates:
35803596
min_batch_size: 10
35813597
default_batch_size: 50
35823598
```
3599+

synapse/config/server.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,26 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
301301
"public_baseurl cannot contain query parameters or a #-fragment"
302302
)
303303

304+
self.extra_well_known_client_content = config.get(
305+
"extra_well_known_client_content", {}
306+
)
307+
308+
if not isinstance(self.extra_well_known_client_content, dict):
309+
raise ConfigError(
310+
"extra_well_known_content must be a dictionary of key-value pairs"
311+
)
312+
313+
if "m.homeserver" in self.extra_well_known_client_content:
314+
raise ConfigError(
315+
"m.homeserver is not supported in extra_well_known_content, "
316+
"use public_baseurl in base config instead."
317+
)
318+
if "m.identity_server" in self.extra_well_known_client_content:
319+
raise ConfigError(
320+
"m.identity_server is not supported in extra_well_known_content, "
321+
"use default_identity_server in base config instead."
322+
)
323+
304324
# Whether to enable user presence.
305325
presence_config = config.get("presence") or {}
306326
self.use_presence = presence_config.get("enabled")

synapse/rest/well_known.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
1514
import logging
1615
from typing import TYPE_CHECKING, Optional
1716

@@ -44,6 +43,14 @@ def get_well_known(self) -> Optional[JsonDict]:
4443
"base_url": self._config.registration.default_identity_server
4544
}
4645

46+
if self._config.server.extra_well_known_client_content:
47+
for (
48+
key,
49+
value,
50+
) in self._config.server.extra_well_known_client_content.items():
51+
if key not in result:
52+
result[key] = value
53+
4754
return result
4855

4956

tests/rest/test_well_known.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ def test_client_well_known_no_public_baseurl(self) -> None:
5959

6060
self.assertEqual(channel.code, HTTPStatus.NOT_FOUND)
6161

62+
@unittest.override_config(
63+
{
64+
"public_baseurl": "https://tesths",
65+
"default_identity_server": "https://testis",
66+
"extra_well_known_client_content": {"custom": False},
67+
}
68+
)
69+
def test_client_well_known_custom(self) -> None:
70+
channel = self.make_request(
71+
"GET", "/.well-known/matrix/client", shorthand=False
72+
)
73+
74+
self.assertEqual(channel.code, HTTPStatus.OK)
75+
self.assertEqual(
76+
channel.json_body,
77+
{
78+
"m.homeserver": {"base_url": "https://tesths/"},
79+
"m.identity_server": {"base_url": "https://testis"},
80+
"custom": False,
81+
},
82+
)
83+
6284
@unittest.override_config({"serve_server_wellknown": True})
6385
def test_server_well_known(self) -> None:
6486
channel = self.make_request(

0 commit comments

Comments
 (0)