@@ -499,54 +499,65 @@ def test_large_input_json(self):
499499 f"Expected shape { [1 , shape_size ]} , got { result ['outputs' ][0 ]['shape' ]} " ,
500500 )
501501
502- def test_large_string_in_json (self ):
503- """Test JSON request with large string input"""
504- model = "simple_identity"
505-
506- # Create a string larger than the default 64MB limit but well below INT32
507- # Content-Length max (~2GB) so the server validates JSON size, not header
508- # parsing.
509- large_string_size = DEFAULT_LIMIT_BYTES + OFFSET_ELEMENTS
510- large_string = "A" * large_string_size
511-
502+ def _build_string_body_of_size (self , target_size ):
503+ """Build a JSON inference request body that is exactly target_size bytes."""
512504 payload = {
513505 "inputs" : [
514506 {
515507 "name" : "INPUT0" ,
516508 "datatype" : "BYTES" ,
517509 "shape" : [1 , 1 ],
518- "data" : [large_string ],
510+ "data" : ["" ],
519511 }
520512 ]
521513 }
514+ overhead = len (json .dumps (payload ))
515+ pad = target_size - overhead
516+ assert pad >= 0 , "target_size smaller than payload overhead"
517+ payload ["inputs" ][0 ]["data" ] = ["A" * pad ]
518+ body = json .dumps (payload )
519+ assert len (body ) == target_size , (len (body ), target_size )
520+ return body
522521
522+ def test_large_string_in_json (self ):
523+ """Verify the server's JSON size limit at the byte boundary.
524+
525+ Uses a body well below the INT32 Content-Length max (~2GB) so the
526+ server's JSON-size check fires deterministically rather than failing
527+ in Content-Length header parsing.
528+ """
529+ model = "simple_identity"
523530 headers = {"Content-Type" : "application/json" }
531+
532+ # 1 byte over the 64 MiB default limit must be rejected with the
533+ # size-limit error.
534+ body_over = self ._build_string_body_of_size (DEFAULT_LIMIT_BYTES + 1 )
524535 response = requests .post (
525- self ._get_infer_url (model ), headers = headers , json = payload
536+ self ._get_infer_url (model ), data = body_over , headers = headers
526537 )
527-
528- # Should fail with 400 bad request
529538 self .assertEqual (
530539 400 ,
531540 response .status_code ,
532- "Expected error code for oversized JSON request , got: {}" .format (
533- response .status_code
541+ "Expected 400 for body of DEFAULT_LIMIT_BYTES + 1 , got: {} ({!r}) " .format (
542+ response .status_code , response . content [: 200 ]
534543 ),
535544 )
536-
537- # Verify error message
538545 error_msg = response .content .decode ()
539- self .assertIn (
540- "request JSON size of " ,
541- error_msg ,
542- )
543- self .assertIn (
544- " bytes exceeds the maximum allowed input size of " ,
545- error_msg ,
546+ self .assertIn ("request JSON size of " , error_msg )
547+ self .assertIn (" bytes exceeds the maximum allowed input size of " , error_msg )
548+ self .assertIn ("Use --http-max-input-size to increase the limit." , error_msg )
549+
550+ # Exactly at the limit must pass the size check.
551+ body_at = self ._build_string_body_of_size (DEFAULT_LIMIT_BYTES )
552+ response = requests .post (
553+ self ._get_infer_url (model ), data = body_at , headers = headers
546554 )
547- self .assertIn (
548- "Use --http-max-input-size to increase the limit." ,
549- error_msg ,
555+ self .assertEqual (
556+ 200 ,
557+ response .status_code ,
558+ "Expected 200 for body of exactly DEFAULT_LIMIT_BYTES, got: {} ({!r})" .format (
559+ response .status_code , response .content [:200 ]
560+ ),
550561 )
551562
552563 def _create_compressed_payload (self , target_size ):
0 commit comments