@@ -1029,26 +1029,41 @@ public function testPostMaxFileSizeIgnoredByFilesComingBeforeIt()
1029
1029
1030
1030
public function testWeOnlyParseTheAmountOfMultiPartChunksWeConfigured ()
1031
1031
{
1032
+ $ chunkCount = 5000000 ;
1032
1033
$ boundary = "---------------------------12758086162038677464950549563 " ;
1033
1034
1034
1035
$ chunk = "-- $ boundary \r\n" ;
1035
1036
$ chunk .= "Content-Disposition: form-data; name= \"f \"\r\n" ;
1036
1037
$ chunk .= "\r\n" ;
1037
1038
$ chunk .= "u \r\n" ;
1038
1039
$ data = '' ;
1039
- for ($ i = 0 ; $ i < 5000000 ; $ i ++) {
1040
- $ data .= $ chunk ;
1041
- }
1040
+ $ data .= str_repeat ($ chunk , $ chunkCount );
1042
1041
$ data .= "-- $ boundary-- \r\n" ;
1043
1042
1044
1043
$ request = new ServerRequest ('POST ' , 'http://example.com/ ' , array (
1045
1044
'Content-Type ' => 'multipart/form-data; boundary= ' . $ boundary ,
1046
1045
), $ data , 1.1 );
1047
1046
1048
1047
$ parser = new MultipartParser ();
1049
- $ startTime = microtime (true );
1050
- $ parser ->parse ($ request );
1051
- $ runTime = microtime (true ) - $ startTime ;
1052
- $ this ->assertLessThan (1 , $ runTime );
1048
+
1049
+ $ reflectecClass = new \ReflectionClass ('\React\Http\Io\MultipartParser ' );
1050
+ $ requestProperty = $ reflectecClass ->getProperty ('request ' );
1051
+ $ requestProperty ->setAccessible (true );
1052
+ $ cursorProperty = $ reflectecClass ->getProperty ('cursor ' );
1053
+ $ cursorProperty ->setAccessible (true );
1054
+ $ multipartBodyPartCountProperty = $ reflectecClass ->getProperty ('multipartBodyPartCount ' );
1055
+ $ multipartBodyPartCountProperty ->setAccessible (true );
1056
+ $ maxMultipartBodyPartsProperty = $ reflectecClass ->getProperty ('maxMultipartBodyParts ' );
1057
+ $ maxMultipartBodyPartsProperty ->setAccessible (true );
1058
+ $ parseBodyMethod = $ reflectecClass ->getMethod ('parseBody ' );
1059
+ $ parseBodyMethod ->setAccessible (true );
1060
+
1061
+ $ this ->assertSame (0 , $ cursorProperty ->getValue ($ parser ));
1062
+
1063
+ $ requestProperty ->setValue ($ parser , $ request );
1064
+ $ parseBodyMethod ->invoke ($ parser , '-- ' . $ boundary , $ data );
1065
+
1066
+ $ this ->assertSame (strlen (str_repeat ($ chunk , $ multipartBodyPartCountProperty ->getValue ($ parser ))), $ cursorProperty ->getValue ($ parser ) + 2 );
1067
+ $ this ->assertSame ($ multipartBodyPartCountProperty ->getValue ($ parser ), $ maxMultipartBodyPartsProperty ->getValue ($ parser ) + 1 );
1053
1068
}
1054
1069
}
0 commit comments