diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2018-05-11 16:07:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-11 16:07:47 +0100 |
commit | c25d7ba12e136a64c4a94964298b66de2e271678 (patch) | |
tree | 0a25aae9a5836826d49ea08f6ec88e2ff5c286fa /synapse/http/site.py | |
parent | Merge pull request #3209 from damir-manapov/master (diff) | |
parent | Set Server header in SynapseRequest (diff) | |
download | synapse-c25d7ba12e136a64c4a94964298b66de2e271678.tar.xz |
Merge pull request #3208 from matrix-org/rav/more_refactor_request_handler
Set Server header in SynapseRequest
Diffstat (limited to 'synapse/http/site.py')
-rw-r--r-- | synapse/http/site.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/synapse/http/site.py b/synapse/http/site.py index bfd9832aa0..202a990508 100644 --- a/synapse/http/site.py +++ b/synapse/http/site.py @@ -77,6 +77,11 @@ class SynapseRequest(Request): def get_user_agent(self): return self.requestHeaders.getRawHeaders(b"User-Agent", [None])[-1] + def render(self, resrc): + # override the Server header which is set by twisted + self.setHeader("Server", self.site.server_version_string) + return Request.render(self, resrc) + def _started_processing(self, servlet_name): self.start_time = int(time.time() * 1000) self.request_metrics = RequestMetrics() @@ -151,6 +156,8 @@ class SynapseRequest(Request): It is possible to update this afterwards by updating self.request_metrics.servlet_name. """ + # TODO: we should probably just move this into render() and finish(), + # to save having to call a separate method. self._started_processing(servlet_name) yield self._finished_processing() @@ -191,7 +198,8 @@ class SynapseSite(Site): Subclass of a twisted http Site that does access logging with python's standard logging """ - def __init__(self, logger_name, site_tag, config, resource, *args, **kwargs): + def __init__(self, logger_name, site_tag, config, resource, + server_version_string, *args, **kwargs): Site.__init__(self, resource, *args, **kwargs) self.site_tag = site_tag @@ -199,6 +207,7 @@ class SynapseSite(Site): proxied = config.get("x_forwarded", False) self.requestFactory = SynapseRequestFactory(self, proxied) self.access_logger = logging.getLogger(logger_name) + self.server_version_string = server_version_string def log(self, request): pass |