diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py
index 901c47f756..776ed43f03 100644
--- a/synapse/http/matrixfederationclient.py
+++ b/synapse/http/matrixfederationclient.py
@@ -92,9 +92,6 @@ incoming_responses_counter = Counter(
"synapse_http_matrixfederationclient_responses", "", ["method", "code"]
)
-# a federation response can be rather large (eg a big state_ids is 50M or so), so we
-# need a generous limit here.
-MAX_RESPONSE_SIZE = 100 * 1024 * 1024
MAX_LONG_RETRIES = 10
MAX_SHORT_RETRIES = 3
@@ -116,6 +113,11 @@ class ByteParser(ByteWriteable, Generic[T], abc.ABC):
the content type doesn't match we fail the request.
"""
+ # a federation response can be rather large (eg a big state_ids is 50M or so), so we
+ # need a generous limit here.
+ MAX_RESPONSE_SIZE: int = 100 * 1024 * 1024
+ """The largest response this parser will accept."""
+
@abc.abstractmethod
def finish(self) -> T:
"""Called when response has finished streaming and the parser should
@@ -203,7 +205,6 @@ async def _handle_response(
response: IResponse,
start_ms: int,
parser: ByteParser[T],
- max_response_size: Optional[int] = None,
) -> T:
"""
Reads the body of a response with a timeout and sends it to a parser
@@ -215,15 +216,12 @@ async def _handle_response(
response: response to the request
start_ms: Timestamp when request was made
parser: The parser for the response
- max_response_size: The maximum size to read from the response, if None
- uses the default.
Returns:
The parsed response
"""
- if max_response_size is None:
- max_response_size = MAX_RESPONSE_SIZE
+ max_response_size = parser.MAX_RESPONSE_SIZE
finished = False
try:
@@ -242,7 +240,7 @@ async def _handle_response(
"{%s} [%s] JSON response exceeded max size %i - %s %s",
request.txn_id,
request.destination,
- MAX_RESPONSE_SIZE,
+ max_response_size,
request.method,
request.uri.decode("ascii"),
)
@@ -783,7 +781,6 @@ class MatrixFederationHttpClient:
backoff_on_404: bool = False,
try_trailing_slash_on_400: bool = False,
parser: Literal[None] = None,
- max_response_size: Optional[int] = None,
) -> Union[JsonDict, list]:
...
@@ -801,7 +798,6 @@ class MatrixFederationHttpClient:
backoff_on_404: bool = False,
try_trailing_slash_on_400: bool = False,
parser: Optional[ByteParser[T]] = None,
- max_response_size: Optional[int] = None,
) -> T:
...
@@ -818,7 +814,6 @@ class MatrixFederationHttpClient:
backoff_on_404: bool = False,
try_trailing_slash_on_400: bool = False,
parser: Optional[ByteParser] = None,
- max_response_size: Optional[int] = None,
):
"""Sends the specified json data using PUT
@@ -854,8 +849,6 @@ class MatrixFederationHttpClient:
enabled.
parser: The parser to use to decode the response. Defaults to
parsing as JSON.
- max_response_size: The maximum size to read from the response, if None
- uses the default.
Returns:
Succeeds when we get a 2xx HTTP response. The
@@ -906,7 +899,6 @@ class MatrixFederationHttpClient:
response,
start_ms,
parser=parser,
- max_response_size=max_response_size,
)
return body
@@ -995,7 +987,6 @@ class MatrixFederationHttpClient:
ignore_backoff: bool = False,
try_trailing_slash_on_400: bool = False,
parser: Literal[None] = None,
- max_response_size: Optional[int] = None,
) -> Union[JsonDict, list]:
...
@@ -1010,7 +1001,6 @@ class MatrixFederationHttpClient:
ignore_backoff: bool = ...,
try_trailing_slash_on_400: bool = ...,
parser: ByteParser[T] = ...,
- max_response_size: Optional[int] = ...,
) -> T:
...
@@ -1024,7 +1014,6 @@ class MatrixFederationHttpClient:
ignore_backoff: bool = False,
try_trailing_slash_on_400: bool = False,
parser: Optional[ByteParser] = None,
- max_response_size: Optional[int] = None,
):
"""GETs some json from the given host homeserver and path
@@ -1054,9 +1043,6 @@ class MatrixFederationHttpClient:
parser: The parser to use to decode the response. Defaults to
parsing as JSON.
- max_response_size: The maximum size to read from the response. If None,
- uses the default.
-
Returns:
Succeeds when we get a 2xx HTTP response. The
result will be the decoded JSON body.
@@ -1101,7 +1087,6 @@ class MatrixFederationHttpClient:
response,
start_ms,
parser=parser,
- max_response_size=max_response_size,
)
return body
|