@@ -205,6 +205,7 @@ async def _handle_response(
205205 response : IResponse ,
206206 start_ms : int ,
207207 parser : ByteParser [T ],
208+ max_response_size : Optional [int ] = None ,
208209) -> T :
209210 """
210211 Reads the body of a response with a timeout and sends it to a parser
@@ -216,15 +217,20 @@ async def _handle_response(
216217 response: response to the request
217218 start_ms: Timestamp when request was made
218219 parser: The parser for the response
220+ max_response_size: The maximum size to read from the response, if None
221+ uses the default.
219222
220223 Returns:
221224 The parsed response
222225 """
223226
227+ if max_response_size is None :
228+ max_response_size = MAX_RESPONSE_SIZE
229+
224230 try :
225231 check_content_type_is (response .headers , parser .CONTENT_TYPE )
226232
227- d = read_body_with_max_size (response , parser , MAX_RESPONSE_SIZE )
233+ d = read_body_with_max_size (response , parser , max_response_size )
228234 d = timeout_deferred (d , timeout = timeout_sec , reactor = reactor )
229235
230236 length = await make_deferred_yieldable (d )
@@ -735,6 +741,7 @@ async def put_json(
735741 backoff_on_404 : bool = False ,
736742 try_trailing_slash_on_400 : bool = False ,
737743 parser : Literal [None ] = None ,
744+ max_response_size : Optional [int ] = None ,
738745 ) -> Union [JsonDict , list ]:
739746 ...
740747
@@ -752,6 +759,7 @@ async def put_json(
752759 backoff_on_404 : bool = False ,
753760 try_trailing_slash_on_400 : bool = False ,
754761 parser : Optional [ByteParser [T ]] = None ,
762+ max_response_size : Optional [int ] = None ,
755763 ) -> T :
756764 ...
757765
@@ -768,6 +776,7 @@ async def put_json(
768776 backoff_on_404 : bool = False ,
769777 try_trailing_slash_on_400 : bool = False ,
770778 parser : Optional [ByteParser ] = None ,
779+ max_response_size : Optional [int ] = None ,
771780 ):
772781 """Sends the specified json data using PUT
773782
@@ -803,6 +812,8 @@ async def put_json(
803812 enabled.
804813 parser: The parser to use to decode the response. Defaults to
805814 parsing as JSON.
815+ max_response_size: The maximum size to read from the response, if None
816+ uses the default.
806817
807818 Returns:
808819 Succeeds when we get a 2xx HTTP response. The
@@ -853,6 +864,7 @@ async def put_json(
853864 response ,
854865 start_ms ,
855866 parser = parser ,
867+ max_response_size = max_response_size ,
856868 )
857869
858870 return body
0 commit comments