@@ -180,6 +180,43 @@ public function requestShouldEmitErrorIfRequestParserThrowsException()
180180 $ request ->handleData ("\r\n\r\n" );
181181 }
182182
183+ public static function provideResponseHeaderOverflow ()
184+ {
185+ $ data = "HTTP/1.1 200 OK \r\nContent-Length: 0 \r\nX-Data: " ;
186+ $ data .= str_repeat ('A ' , 65537 - strlen ($ data )) . "\r\n\r\n" ;
187+
188+ $ legacy = "HTTP/1.1 200 OK \r\n" ;
189+ $ legacy .= str_repeat ('A ' , 65537 - strlen ($ legacy )) . "\n\n" ;
190+
191+ return array (
192+ 'without end of message ' => array (str_repeat ('A ' , 65537 )),
193+ 'with end of message ' => array ($ data ),
194+ 'with legacy end of message ' => array ($ legacy ),
195+ );
196+ }
197+
198+ /**
199+ * @dataProvider provideResponseHeaderOverflow
200+ * @param string $data
201+ */
202+ public function testRequestShouldEmitErrorWhenResponseHeadersExceedMaximumSize ($ data )
203+ {
204+ $ connection = $ this ->getMockBuilder ('React\Socket\ConnectionInterface ' )->getMock ();
205+
206+ $ connectionManager = $ this ->getMockBuilder ('React\Http\Io\ClientConnectionManager ' )->disableOriginalConstructor ()->getMock ();
207+ $ connectionManager ->expects ($ this ->once ())->method ('connect ' )->willReturn (\React \Promise \resolve ($ connection ));
208+
209+ $ requestData = new Request ('GET ' , 'http://www.example.com ' );
210+ $ request = new ClientRequestStream ($ connectionManager , $ requestData );
211+
212+ $ request ->on ('response ' , $ this ->expectCallableNever ());
213+ $ request ->on ('error ' , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('OverflowException ' )));
214+ $ request ->on ('close ' , $ this ->expectCallableOnce ());
215+
216+ $ request ->end ();
217+ $ request ->handleData ($ data );
218+ }
219+
183220 /** @test */
184221 public function getRequestShouldSendAGetRequest ()
185222 {
0 commit comments