コード例 #1
0
ファイル: homeserver.py プロジェクト: cuongnv/synapse
    def _listener_http(self, config, listener_config):
        port = listener_config["port"]
        bind_addresses = listener_config["bind_addresses"]
        tls = listener_config.get("tls", False)
        site_tag = listener_config.get("tag", port)

        if tls and config.no_tls:
            return

        resources = {}
        for res in listener_config["resources"]:
            for name in res["names"]:
                resources.update(self._configure_named_resource(
                    name, res.get("compress", False),
                ))

        additional_resources = listener_config.get("additional_resources", {})
        logger.debug("Configuring additional resources: %r",
                     additional_resources)
        module_api = ModuleApi(self, self.get_auth_handler())
        for path, resmodule in additional_resources.items():
            handler_cls, config = load_module(resmodule)
            handler = handler_cls(config, module_api)
            resources[path] = AdditionalResource(self, handler.handle_request)

        #if WEB_CLIENT_PREFIX in resources:
        #    root_resource = RootRedirect(WEB_CLIENT_PREFIX)
        #else:
        #    root_resource = NoResource()
        root_resource = NoResource()

        root_resource = create_resource_tree(resources, root_resource)

        if tls:
            listen_ssl(
                bind_addresses,
                port,
                SynapseSite(
                    "synapse.access.https.%s" % (site_tag,),
                    site_tag,
                    listener_config,
                    root_resource,
                    self.version_string,
                ),
                self.tls_server_context_factory,
            )

        else:
            listen_tcp(
                bind_addresses,
                port,
                SynapseSite(
                    "synapse.access.http.%s" % (site_tag,),
                    site_tag,
                    listener_config,
                    root_resource,
                    self.version_string,
                )
            )
        logger.info("Synapse now listening on port %d", port)
コード例 #2
0
    def test_sync(self):
        handler = _SyncTestCustomEndpoint({}, None).handle_request
        self.resource = AdditionalResource(self.hs, handler)

        request, channel = self.make_request("GET", "/")
        self.render(request)

        self.assertEqual(request.code, 200)
        self.assertEqual(channel.json_body, {"some_key": "some_value_sync"})