92
92
"synapse_http_matrixfederationclient_responses" , "" , ["method" , "code" ]
93
93
)
94
94
95
- # a federation response can be rather large (eg a big state_ids is 50M or so), so we
96
- # need a generous limit here.
97
- MAX_RESPONSE_SIZE = 100 * 1024 * 1024
98
95
99
96
MAX_LONG_RETRIES = 10
100
97
MAX_SHORT_RETRIES = 3
@@ -116,6 +113,11 @@ class ByteParser(ByteWriteable, Generic[T], abc.ABC):
116
113
the content type doesn't match we fail the request.
117
114
"""
118
115
116
+ # a federation response can be rather large (eg a big state_ids is 50M or so), so we
117
+ # need a generous limit here.
118
+ MAX_RESPONSE_SIZE : int = 100 * 1024 * 1024
119
+ """The largest response this parser will accept."""
120
+
119
121
@abc .abstractmethod
120
122
def finish (self ) -> T :
121
123
"""Called when response has finished streaming and the parser should
@@ -203,7 +205,6 @@ async def _handle_response(
203
205
response : IResponse ,
204
206
start_ms : int ,
205
207
parser : ByteParser [T ],
206
- max_response_size : Optional [int ] = None ,
207
208
) -> T :
208
209
"""
209
210
Reads the body of a response with a timeout and sends it to a parser
@@ -215,15 +216,12 @@ async def _handle_response(
215
216
response: response to the request
216
217
start_ms: Timestamp when request was made
217
218
parser: The parser for the response
218
- max_response_size: The maximum size to read from the response, if None
219
- uses the default.
220
219
221
220
Returns:
222
221
The parsed response
223
222
"""
224
223
225
- if max_response_size is None :
226
- max_response_size = MAX_RESPONSE_SIZE
224
+ max_response_size = parser .MAX_RESPONSE_SIZE
227
225
228
226
try :
229
227
check_content_type_is (response .headers , parser .CONTENT_TYPE )
@@ -240,7 +238,7 @@ async def _handle_response(
240
238
"{%s} [%s] JSON response exceeded max size %i - %s %s" ,
241
239
request .txn_id ,
242
240
request .destination ,
243
- MAX_RESPONSE_SIZE ,
241
+ max_response_size ,
244
242
request .method ,
245
243
request .uri .decode ("ascii" ),
246
244
)
@@ -772,7 +770,6 @@ async def put_json(
772
770
backoff_on_404 : bool = False ,
773
771
try_trailing_slash_on_400 : bool = False ,
774
772
parser : Literal [None ] = None ,
775
- max_response_size : Optional [int ] = None ,
776
773
) -> Union [JsonDict , list ]:
777
774
...
778
775
@@ -790,7 +787,6 @@ async def put_json(
790
787
backoff_on_404 : bool = False ,
791
788
try_trailing_slash_on_400 : bool = False ,
792
789
parser : Optional [ByteParser [T ]] = None ,
793
- max_response_size : Optional [int ] = None ,
794
790
) -> T :
795
791
...
796
792
@@ -807,7 +803,6 @@ async def put_json(
807
803
backoff_on_404 : bool = False ,
808
804
try_trailing_slash_on_400 : bool = False ,
809
805
parser : Optional [ByteParser ] = None ,
810
- max_response_size : Optional [int ] = None ,
811
806
):
812
807
"""Sends the specified json data using PUT
813
808
@@ -843,8 +838,6 @@ async def put_json(
843
838
enabled.
844
839
parser: The parser to use to decode the response. Defaults to
845
840
parsing as JSON.
846
- max_response_size: The maximum size to read from the response, if None
847
- uses the default.
848
841
849
842
Returns:
850
843
Succeeds when we get a 2xx HTTP response. The
@@ -895,7 +888,6 @@ async def put_json(
895
888
response ,
896
889
start_ms ,
897
890
parser = parser ,
898
- max_response_size = max_response_size ,
899
891
)
900
892
901
893
return body
@@ -984,7 +976,6 @@ async def get_json(
984
976
ignore_backoff : bool = False ,
985
977
try_trailing_slash_on_400 : bool = False ,
986
978
parser : Literal [None ] = None ,
987
- max_response_size : Optional [int ] = None ,
988
979
) -> Union [JsonDict , list ]:
989
980
...
990
981
@@ -999,7 +990,6 @@ async def get_json(
999
990
ignore_backoff : bool = ...,
1000
991
try_trailing_slash_on_400 : bool = ...,
1001
992
parser : ByteParser [T ] = ...,
1002
- max_response_size : Optional [int ] = ...,
1003
993
) -> T :
1004
994
...
1005
995
@@ -1013,7 +1003,6 @@ async def get_json(
1013
1003
ignore_backoff : bool = False ,
1014
1004
try_trailing_slash_on_400 : bool = False ,
1015
1005
parser : Optional [ByteParser ] = None ,
1016
- max_response_size : Optional [int ] = None ,
1017
1006
):
1018
1007
"""GETs some json from the given host homeserver and path
1019
1008
@@ -1043,9 +1032,6 @@ async def get_json(
1043
1032
parser: The parser to use to decode the response. Defaults to
1044
1033
parsing as JSON.
1045
1034
1046
- max_response_size: The maximum size to read from the response. If None,
1047
- uses the default.
1048
-
1049
1035
Returns:
1050
1036
Succeeds when we get a 2xx HTTP response. The
1051
1037
result will be the decoded JSON body.
@@ -1090,7 +1076,6 @@ async def get_json(
1090
1076
response ,
1091
1077
start_ms ,
1092
1078
parser = parser ,
1093
- max_response_size = max_response_size ,
1094
1079
)
1095
1080
1096
1081
return body
0 commit comments