From d09099642e3a1fe9b26149fa57c58db3c26afc10 Mon Sep 17 00:00:00 2001
From: Patrick Cloke <clokep@users.noreply.github.com>
Date: Thu, 20 Jan 2022 10:34:45 -0500
Subject: [PATCH] Fix redirecting to the webclient for non-HTTP(S)
 web_client_location. (#11783)

To not change the behaviour during the deprecation period.

Follow-up to #11774.
---
 changelog.d/11783.misc    | 1 +
 synapse/app/homeserver.py | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 changelog.d/11783.misc

diff --git a/changelog.d/11783.misc b/changelog.d/11783.misc
new file mode 100644
index 0000000000..136ba57f94
--- /dev/null
+++ b/changelog.d/11783.misc
@@ -0,0 +1 @@
+Deprecate support for `webclient` listeners and non-HTTP(S) `web_client_location` configuration.
diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py
index 7ef0fdf272..efedcc8889 100644
--- a/synapse/app/homeserver.py
+++ b/synapse/app/homeserver.py
@@ -131,11 +131,18 @@ class SynapseHomeServer(HomeServer):
         resources.update(self._module_web_resources)
         self._module_web_resources_consumed = True
 
-        # try to find something useful to redirect '/' to
+        # Try to find something useful to serve at '/':
+        #
+        # 1. Redirect to the web client if it is an HTTP(S) URL.
+        # 2. Redirect to the web client served via Synapse.
+        # 3. Redirect to the static "Synapse is running" page.
+        # 4. Do not redirect and use a blank resource.
         if self.config.server.web_client_location_is_redirect:
             root_resource: Resource = RootOptionsRedirectResource(
                 self.config.server.web_client_location
             )
+        elif WEB_CLIENT_PREFIX in resources:
+            root_resource = RootOptionsRedirectResource(WEB_CLIENT_PREFIX)
         elif STATIC_PREFIX in resources:
             root_resource = RootOptionsRedirectResource(STATIC_PREFIX)
         else:
-- 
GitLab