summary refs log tree commit diff
path: root/synapse/rest
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew.hodgson@openmarket.com>2014-08-13 16:14:30 +0100
committerMatthew Hodgson <matthew.hodgson@openmarket.com>2014-08-13 16:14:30 +0100
commit2ec5f6c2f2bccca6fe3004fd7d4c2632428a4ba5 (patch)
tree93449489f2a1244b4f807f79fed5e23446d60e56 /synapse/rest
parenttimestamps (diff)
parentDon't pass host_web_client flag to register_servlets, it needs to be a Resour... (diff)
downloadsynapse-2ec5f6c2f2bccca6fe3004fd7d4c2632428a4ba5.tar.xz
Merge branch 'master' of git+ssh://github.com/matrix-org/synapse
Diffstat (limited to 'synapse/rest')
-rw-r--r--synapse/rest/__init__.py10
-rw-r--r--synapse/rest/base.py43
-rw-r--r--synapse/rest/directory.py1
-rw-r--r--synapse/rest/events.py1
-rw-r--r--synapse/rest/im.py1
-rw-r--r--synapse/rest/login.py1
-rw-r--r--synapse/rest/presence.py1
-rw-r--r--synapse/rest/profile.py1
-rw-r--r--synapse/rest/public.py1
-rw-r--r--synapse/rest/register.py1
-rw-r--r--synapse/rest/room.py1
-rw-r--r--synapse/rest/webclient.py45
12 files changed, 63 insertions, 44 deletions
diff --git a/synapse/rest/__init__.py b/synapse/rest/__init__.py
index 5598295793..74a372e2ff 100644
--- a/synapse/rest/__init__.py
+++ b/synapse/rest/__init__.py
@@ -13,10 +13,13 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+
 from . import (
-    room, events, register, profile, public, presence, im, directory
+    room, events, register, login, profile, public, presence, im, directory,
+    webclient
 )
 
+
 class RestServletFactory(object):
 
     """ A factory for creating REST servlets.
@@ -35,10 +38,13 @@ class RestServletFactory(object):
         room.register_servlets(hs, http_server)
         events.register_servlets(hs, http_server)
         register.register_servlets(hs, http_server)
+        login.register_servlets(hs, http_server)
         profile.register_servlets(hs, http_server)
         public.register_servlets(hs, http_server)
         presence.register_servlets(hs, http_server)
         im.register_servlets(hs, http_server)
         directory.register_servlets(hs, http_server)
 
-
+    def register_web_client(self, hs):
+        http_server = hs.get_http_server()
+        webclient.register_servlets(hs, http_server)
diff --git a/synapse/rest/base.py b/synapse/rest/base.py
index d90ac611fe..65d417f757 100644
--- a/synapse/rest/base.py
+++ b/synapse/rest/base.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 """ This module contains base REST classes for constructing REST servlets. """
 import re
 
@@ -29,48 +30,6 @@ def client_path_pattern(path_regex):
     return re.compile("^/matrix/client/api/v1" + path_regex)
 
 
-class RestServletFactory(object):
-
-    """ A factory for creating REST servlets.
-
-    These REST servlets represent the entire client-server REST API. Generally
-    speaking, they serve as wrappers around events and the handlers that
-    process them.
-
-    See synapse.api.events for information on synapse events.
-    """
-
-    def __init__(self, hs):
-        http_server = hs.get_http_server()
-
-        # You get import errors if you try to import before the classes in this
-        # file are defined, hence importing here instead.
-
-        import room
-        room.register_servlets(hs, http_server)
-
-        import events
-        events.register_servlets(hs, http_server)
-
-        import register
-        register.register_servlets(hs, http_server)
-
-        import profile
-        profile.register_servlets(hs, http_server)
-
-        import public
-        public.register_servlets(hs, http_server)
-
-        import presence
-        presence.register_servlets(hs, http_server)
-
-        import im
-        im.register_servlets(hs, http_server)
-
-        import login
-        login.register_servlets(hs, http_server)
-
-
 class RestServlet(object):
 
     """ A Synapse REST Servlet.
diff --git a/synapse/rest/directory.py b/synapse/rest/directory.py
index a426003a38..31fd26e848 100644
--- a/synapse/rest/directory.py
+++ b/synapse/rest/directory.py
@@ -13,6 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+
 from twisted.internet import defer
 
 from synapse.types import RoomAlias, RoomID
diff --git a/synapse/rest/events.py b/synapse/rest/events.py
index 147257a940..dc811b813a 100644
--- a/synapse/rest/events.py
+++ b/synapse/rest/events.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 """This module contains REST servlets to do with event streaming, /events."""
 from twisted.internet import defer
 
diff --git a/synapse/rest/im.py b/synapse/rest/im.py
index 39f2dbd749..63a77716a0 100644
--- a/synapse/rest/im.py
+++ b/synapse/rest/im.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 from twisted.internet import defer
 
 from synapse.api.streams import PaginationConfig
diff --git a/synapse/rest/login.py b/synapse/rest/login.py
index 0284e125b4..88a3218332 100644
--- a/synapse/rest/login.py
+++ b/synapse/rest/login.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 from twisted.internet import defer
 
 from synapse.api.errors import SynapseError
diff --git a/synapse/rest/presence.py b/synapse/rest/presence.py
index e4925c20a5..6043848595 100644
--- a/synapse/rest/presence.py
+++ b/synapse/rest/presence.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 """ This module contains REST servlets to do with presence: /presence/<paths>
 """
 from twisted.internet import defer
diff --git a/synapse/rest/profile.py b/synapse/rest/profile.py
index f384227c29..3d0427bf72 100644
--- a/synapse/rest/profile.py
+++ b/synapse/rest/profile.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 """ This module contains REST servlets to do with profile: /profile/<paths> """
 from twisted.internet import defer
 
diff --git a/synapse/rest/public.py b/synapse/rest/public.py
index 6fd1731a61..3430c8049f 100644
--- a/synapse/rest/public.py
+++ b/synapse/rest/public.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 """This module contains REST servlets to do with public paths: /public"""
 from twisted.internet import defer
 
diff --git a/synapse/rest/register.py b/synapse/rest/register.py
index f1cbce5c67..eb457562b9 100644
--- a/synapse/rest/register.py
+++ b/synapse/rest/register.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 """This module contains REST servlets to do with registration: /register"""
 from twisted.internet import defer
 
diff --git a/synapse/rest/room.py b/synapse/rest/room.py
index c96de5e65d..228bc9623d 100644
--- a/synapse/rest/room.py
+++ b/synapse/rest/room.py
@@ -12,6 +12,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+
 """ This module contains REST servlets to do with rooms: /rooms/<paths> """
 from twisted.internet import defer
 
diff --git a/synapse/rest/webclient.py b/synapse/rest/webclient.py
new file mode 100644
index 0000000000..75a425c14c
--- /dev/null
+++ b/synapse/rest/webclient.py
@@ -0,0 +1,45 @@
+# -*- coding: utf-8 -*-
+# Copyright 2014 matrix.org
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from synapse.rest.base import RestServlet
+
+import logging
+import re
+
+logger = logging.getLogger(__name__)
+
+
+class WebClientRestServlet(RestServlet):
+    # No PATTERN; we have custom dispatch rules here
+
+    def register(self, http_server):
+        http_server.register_path("GET",
+                                  re.compile("^/$"),
+                                  self.on_GET_redirect)
+        http_server.register_path("GET",
+                                  re.compile("^/matrix/client$"),
+                                  self.on_GET)
+
+    def on_GET(self, request):
+        return (200, "not implemented")
+
+    def on_GET_redirect(self, request):
+        request.setHeader("Location", request.uri + "matrix/client")
+        return (302, None)
+
+
+def register_servlets(hs, http_server):
+    logger.info("Registering web client.")
+    WebClientRestServlet(hs).register(http_server)
\ No newline at end of file