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