diff options
author | Erik Johnston <erik@matrix.org> | 2014-08-15 11:50:14 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-08-15 11:50:14 +0100 |
commit | d72f897f078fa72548522440149369293f0d12b2 (patch) | |
tree | 4e8d692713f73389b89dea4fdba719b696c9f3af /synapse/http/server.py | |
parent | Reimplement the get public rooms api to work with new DB schema (diff) | |
parent | Add a check to make sure that during state conflict res we only request a PDU... (diff) | |
download | synapse-d72f897f078fa72548522440149369293f0d12b2.tar.xz |
Merge branch 'master' of github.com:matrix-org/synapse into sql_refactor
Conflicts: synapse/storage/stream.py
Diffstat (limited to 'synapse/http/server.py')
-rw-r--r-- | synapse/http/server.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py index d7f4b691bc..bad2738bde 100644 --- a/synapse/http/server.py +++ b/synapse/http/server.py @@ -22,6 +22,7 @@ from synapse.api.errors import cs_exception, CodeMessageException from twisted.internet import defer, reactor from twisted.web import server, resource from twisted.web.server import NOT_DONE_YET +from twisted.web.util import redirectTo import collections import logging @@ -52,10 +53,9 @@ class HttpServer(object): pass -# The actual HTTP server impl, using twisted http server -class TwistedHttpServer(HttpServer, resource.Resource): - """ This wraps the twisted HTTP server, and triggers the correct callbacks - on the transport_layer. +class JsonResource(HttpServer, resource.Resource): + """ This implements the HttpServer interface and provides JSON support for + Resources. Register callbacks via register_path() """ @@ -160,6 +160,22 @@ class TwistedHttpServer(HttpServer, resource.Resource): return False +class RootRedirect(resource.Resource): + """Redirects the root '/' path to another path.""" + + def __init__(self, path): + resource.Resource.__init__(self) + self.url = path + + def render_GET(self, request): + return redirectTo(self.url, request) + + def getChild(self, name, request): + if len(name) == 0: + return self # select ourselves as the child to render + return resource.Resource.getChild(self, name, request) + + def respond_with_json_bytes(request, code, json_bytes, send_cors=False): """Sends encoded JSON in response to the given request. |