Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Cargo.lock
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to this PR, but appears to be needed on develop after #18589. Though I'm not entirely sure why...

Fine to keep in this PR IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, weird

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions changelog.d/18600.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Better handling of ratelimited requests.
2 changes: 1 addition & 1 deletion synapse/http/additional_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
hs: homeserver
handler: function to be called to handle the request.
"""
super().__init__(hs.get_clock())
super().__init__(clock=hs.get_clock())
self._handler = handler

async def _async_render(self, request: Request) -> Optional[Tuple[int, Any]]:
Expand Down
15 changes: 12 additions & 3 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@
Protocol,
Tuple,
Union,
cast,
)

import attr
import jinja2
from canonicaljson import encode_canonical_json
from zope.interface import implementer

from twisted.internet import defer, interfaces
from twisted.internet import defer, interfaces, reactor
from twisted.internet.defer import CancelledError
from twisted.internet.interfaces import IReactorTime
from twisted.python import failure
from twisted.web import resource

Expand Down Expand Up @@ -401,8 +403,15 @@ class DirectServeJsonResource(_AsyncResource):
"""

def __init__(
self, clock: Clock, canonical_json: bool = False, extract_context: bool = False
self,
canonical_json: bool = False,
extract_context: bool = False,
# Clock is optional as this class is exposed to the module API.
clock: Optional[Clock] = None,
):
if clock is None:
clock = Clock(cast(IReactorTime, reactor))

super().__init__(clock, extract_context)
self.canonical_json = canonical_json

Expand Down Expand Up @@ -460,7 +469,7 @@ def __init__(
extract_context: bool = False,
):
self.clock = hs.get_clock()
super().__init__(self.clock, canonical_json, extract_context)
super().__init__(canonical_json, extract_context, clock=self.clock)
# Map of path regex -> method -> callback.
self._routes: Dict[Pattern[str], Dict[bytes, _PathEntry]] = {}
self.hs = hs
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/synapse/client/federation_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FederationWhitelistResource(DirectServeJsonResource):
PATH = "/_synapse/client/v1/config/federation_whitelist"

def __init__(self, hs: "HomeServer"):
super().__init__(hs.get_clock())
super().__init__(clock=hs.get_clock())

self._federation_whitelist = hs.config.federation.federation_domain_whitelist

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/synapse/client/jwks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

class JwksResource(DirectServeJsonResource):
def __init__(self, hs: "HomeServer"):
super().__init__(hs.get_clock(), extract_context=True)
super().__init__(clock=hs.get_clock(), extract_context=True)

# Parameters that are allowed to be exposed in the public key.
# This is done manually, because authlib's private to public key conversion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class OIDCBackchannelLogoutResource(DirectServeJsonResource):
isLeaf = 1

def __init__(self, hs: "HomeServer"):
super().__init__(hs.get_clock())
super().__init__(clock=hs.get_clock())
self._oidc_handler = hs.get_oidc_handler()

async def _async_render_POST(self, request: SynapseRequest) -> None:
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/synapse/client/pick_username.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def pick_username_resource(hs: "HomeServer") -> Resource:

class AvailabilityCheckResource(DirectServeJsonResource):
def __init__(self, hs: "HomeServer"):
super().__init__(hs.get_clock())
super().__init__(clock=hs.get_clock())
self._sso_handler = hs.get_sso_handler()

async def _async_render_GET(self, request: Request) -> Tuple[int, JsonDict]:
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/synapse/client/rendezvous.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MSC4108RendezvousSessionResource(DirectServeJsonResource):
isLeaf = True

def __init__(self, hs: "HomeServer") -> None:
super().__init__(hs.get_clock())
super().__init__(clock=hs.get_clock())
self._handler = hs.get_rendezvous_handler()

async def _async_render_GET(self, request: SynapseRequest) -> None:
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/well_known.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ClientWellKnownResource(DirectServeJsonResource):
isLeaf = 1

def __init__(self, hs: "HomeServer"):
super().__init__(hs.get_clock())
super().__init__(clock=hs.get_clock())
self._well_known_builder = WellKnownBuilder(hs)

async def _async_render_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ async def callback(request: SynapseRequest) -> None:

class CancellableDirectServeJsonResource(DirectServeJsonResource):
def __init__(self, clock: Clock):
super().__init__(clock)
super().__init__(clock=clock)
self.clock = clock

@cancellable
Expand Down
Loading