@@ -185,6 +185,7 @@ def __init__( # noqa: PLR0913
185185 [AgentCard , ServerCallContext ], AgentCard
186186 ]
187187 | None = None ,
188+ disable_content_length_check : bool = False ,
188189 ) -> None :
189190 """Initializes the JSONRPCApplication.
190191
@@ -202,6 +203,8 @@ def __init__( # noqa: PLR0913
202203 extended_card_modifier: An optional callback to dynamically modify
203204 the extended agent card before it is served. It receives the
204205 call context.
206+ disable_content_length_check: An optional, if True disables the check
207+ for oversized payloads.
205208 """
206209 if not _package_starlette_installed :
207210 raise ImportError (
@@ -220,6 +223,7 @@ def __init__( # noqa: PLR0913
220223 extended_card_modifier = extended_card_modifier ,
221224 )
222225 self ._context_builder = context_builder or DefaultCallContextBuilder ()
226+ self ._disable_content_length_check = disable_content_length_check
223227
224228 def _generate_error_response (
225229 self , request_id : str | int | None , error : JSONRPCError | A2AError
@@ -291,18 +295,22 @@ async def _handle_requests(self, request: Request) -> Response: # noqa: PLR0911
291295 request_id , str | int
292296 ):
293297 request_id = None
294- # Treat very large payloads as invalid request (-32600) before routing
295- with contextlib .suppress (Exception ):
296- content_length = int (request .headers .get ('content-length' , '0' ))
297- if content_length and content_length > MAX_CONTENT_LENGTH :
298- return self ._generate_error_response (
299- request_id ,
300- A2AError (
301- root = InvalidRequestError (
302- message = 'Payload too large'
303- )
304- ),
298+ # If content lenght check is not diasbled,
299+ # treat very large payloads as invalid request (-32600) before routing
300+ if not self ._disable_content_length_check :
301+ with contextlib .suppress (Exception ):
302+ content_length = int (
303+ request .headers .get ('content-length' , '0' )
305304 )
305+ if content_length and content_length > MAX_CONTENT_LENGTH :
306+ return self ._generate_error_response (
307+ request_id ,
308+ A2AError (
309+ root = InvalidRequestError (
310+ message = 'Payload too large'
311+ )
312+ ),
313+ )
306314 logger .debug ('Request body: %s' , body )
307315 # 1) Validate base JSON-RPC structure only (-32600 on failure)
308316 try :
0 commit comments