Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Kill off redundant SynapseRequestFactory (#6619)
Browse files Browse the repository at this point in the history
* commit 'b6b57ecb4':
  Kill off redundant SynapseRequestFactory (#6619)
  • Loading branch information
anoadragon453 committed Mar 20, 2020
2 parents a54d17c + b6b57ec commit 6d9f40c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
1 change: 1 addition & 0 deletions changelog.d/6619.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Simplify http handling by removing redundant SynapseRequestFactory.
18 changes: 3 additions & 15 deletions synapse/http/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class SynapseRequest(Request):
logcontext(LoggingContext) : the log context for this request
"""

def __init__(self, site, channel, *args, **kw):
def __init__(self, channel, *args, **kw):
Request.__init__(self, channel, *args, **kw)
self.site = site
self.site = channel.site
self._channel = channel # this is used by the tests
self.authenticated_entity = None
self.start_time = 0
Expand Down Expand Up @@ -331,18 +331,6 @@ def getClientIP(self):
)


class SynapseRequestFactory(object):
def __init__(self, site, x_forwarded_for):
self.site = site
self.x_forwarded_for = x_forwarded_for

def __call__(self, *args, **kwargs):
if self.x_forwarded_for:
return XForwardedForRequest(self.site, *args, **kwargs)
else:
return SynapseRequest(self.site, *args, **kwargs)


class SynapseSite(Site):
"""
Subclass of a twisted http Site that does access logging with python's
Expand All @@ -364,7 +352,7 @@ def __init__(
self.site_tag = site_tag

proxied = config.get("x_forwarded", False)
self.requestFactory = SynapseRequestFactory(self, proxied)
self.requestFactory = XForwardedForRequest if proxied else SynapseRequest
self.access_logger = logging.getLogger(logger_name)
self.server_version_string = server_version_string.encode("ascii")

Expand Down
6 changes: 4 additions & 2 deletions tests/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from twisted.test.proto_helpers import AccumulatingProtocol, MemoryReactorClock
from twisted.web.http import unquote
from twisted.web.http_headers import Headers
from twisted.web.server import Site

from synapse.http.site import SynapseRequest
from synapse.util import Clock
Expand All @@ -42,6 +43,7 @@ class FakeChannel(object):
wire).
"""

site = attr.ib(type=Site)
_reactor = attr.ib()
result = attr.ib(default=attr.Factory(dict))
_producer = None
Expand Down Expand Up @@ -176,9 +178,9 @@ def make_request(
content = content.encode("utf8")

site = FakeSite()
channel = FakeChannel(reactor)
channel = FakeChannel(site, reactor)

req = request(site, channel)
req = request(channel)
req.process = lambda: b""
req.content = BytesIO(content)
req.postpath = list(map(unquote, path[1:].split(b"/")))
Expand Down

0 comments on commit 6d9f40c

Please sign in to comment.