forked from MirrorHub/synapse
Merge pull request #2625 from matrix-org/rav/named_resource_refactor
Factor out _configure_named_resource
This commit is contained in:
commit
77e3757fa9
1 changed files with 64 additions and 46 deletions
|
@ -107,9 +107,59 @@ class SynapseHomeServer(HomeServer):
|
||||||
resources = {}
|
resources = {}
|
||||||
for res in listener_config["resources"]:
|
for res in listener_config["resources"]:
|
||||||
for name in res["names"]:
|
for name in res["names"]:
|
||||||
|
resources.update(self._configure_named_resource(
|
||||||
|
name, res.get("compress", False),
|
||||||
|
))
|
||||||
|
|
||||||
|
if WEB_CLIENT_PREFIX in resources:
|
||||||
|
root_resource = RootRedirect(WEB_CLIENT_PREFIX)
|
||||||
|
else:
|
||||||
|
root_resource = Resource()
|
||||||
|
|
||||||
|
root_resource = create_resource_tree(resources, root_resource)
|
||||||
|
|
||||||
|
if tls:
|
||||||
|
for address in bind_addresses:
|
||||||
|
reactor.listenSSL(
|
||||||
|
port,
|
||||||
|
SynapseSite(
|
||||||
|
"synapse.access.https.%s" % (site_tag,),
|
||||||
|
site_tag,
|
||||||
|
listener_config,
|
||||||
|
root_resource,
|
||||||
|
),
|
||||||
|
self.tls_server_context_factory,
|
||||||
|
interface=address
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
for address in bind_addresses:
|
||||||
|
reactor.listenTCP(
|
||||||
|
port,
|
||||||
|
SynapseSite(
|
||||||
|
"synapse.access.http.%s" % (site_tag,),
|
||||||
|
site_tag,
|
||||||
|
listener_config,
|
||||||
|
root_resource,
|
||||||
|
),
|
||||||
|
interface=address
|
||||||
|
)
|
||||||
|
logger.info("Synapse now listening on port %d", port)
|
||||||
|
|
||||||
|
def _configure_named_resource(self, name, compress=False):
|
||||||
|
"""Build a resource map for a named resource
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name (str): named resource: one of "client", "federation", etc
|
||||||
|
compress (bool): whether to enable gzip compression for this
|
||||||
|
resource
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict[str, Resource]: map from path to HTTP resource
|
||||||
|
"""
|
||||||
|
resources = {}
|
||||||
if name == "client":
|
if name == "client":
|
||||||
client_resource = ClientRestResource(self)
|
client_resource = ClientRestResource(self)
|
||||||
if res["compress"]:
|
if compress:
|
||||||
client_resource = gz_wrap(client_resource)
|
client_resource = gz_wrap(client_resource)
|
||||||
|
|
||||||
resources.update({
|
resources.update({
|
||||||
|
@ -154,39 +204,7 @@ class SynapseHomeServer(HomeServer):
|
||||||
if name == "metrics" and self.get_config().enable_metrics:
|
if name == "metrics" and self.get_config().enable_metrics:
|
||||||
resources[METRICS_PREFIX] = MetricsResource(self)
|
resources[METRICS_PREFIX] = MetricsResource(self)
|
||||||
|
|
||||||
if WEB_CLIENT_PREFIX in resources:
|
return resources
|
||||||
root_resource = RootRedirect(WEB_CLIENT_PREFIX)
|
|
||||||
else:
|
|
||||||
root_resource = Resource()
|
|
||||||
|
|
||||||
root_resource = create_resource_tree(resources, root_resource)
|
|
||||||
|
|
||||||
if tls:
|
|
||||||
for address in bind_addresses:
|
|
||||||
reactor.listenSSL(
|
|
||||||
port,
|
|
||||||
SynapseSite(
|
|
||||||
"synapse.access.https.%s" % (site_tag,),
|
|
||||||
site_tag,
|
|
||||||
listener_config,
|
|
||||||
root_resource,
|
|
||||||
),
|
|
||||||
self.tls_server_context_factory,
|
|
||||||
interface=address
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
for address in bind_addresses:
|
|
||||||
reactor.listenTCP(
|
|
||||||
port,
|
|
||||||
SynapseSite(
|
|
||||||
"synapse.access.http.%s" % (site_tag,),
|
|
||||||
site_tag,
|
|
||||||
listener_config,
|
|
||||||
root_resource,
|
|
||||||
),
|
|
||||||
interface=address
|
|
||||||
)
|
|
||||||
logger.info("Synapse now listening on port %d", port)
|
|
||||||
|
|
||||||
def start_listening(self):
|
def start_listening(self):
|
||||||
config = self.get_config()
|
config = self.get_config()
|
||||||
|
|
Loading…
Reference in a new issue