@@ -36,6 +36,18 @@ public function setUp()
3636 ->getMock ();
3737 }
3838
39+ public function testRequestEventWillNotBeEmittedForIncompleteHeaders ()
40+ {
41+ $ server = new Server ($ this ->socket );
42+ $ server ->on ('request ' , $ this ->expectCallableNever ());
43+
44+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
45+
46+ $ data = '' ;
47+ $ data .= "GET / HTTP/1.1 \r\n" ;
48+ $ this ->connection ->emit ('data ' , array ($ data ));
49+ }
50+
3951 public function testRequestEventIsEmitted ()
4052 {
4153 $ server = new Server ($ this ->socket );
@@ -79,6 +91,62 @@ public function testRequestEvent()
7991 $ this ->assertInstanceOf ('React\Http\Response ' , $ responseAssertion );
8092 }
8193
94+ public function testRequestEventWithoutBodyWillNotEmitData ()
95+ {
96+ $ never = $ this ->expectCallableNever ();
97+
98+ $ server = new Server ($ this ->socket );
99+ $ server ->on ('request ' , function (Request $ request ) use ($ never ) {
100+ $ request ->on ('data ' , $ never );
101+ });
102+
103+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
104+
105+ $ data = $ this ->createGetRequest ();
106+ $ this ->connection ->emit ('data ' , array ($ data ));
107+ }
108+
109+ public function testRequestEventWithSecondDataEventWillEmitBodyData ()
110+ {
111+ $ once = $ this ->expectCallableOnceWith ('incomplete ' );
112+
113+ $ server = new Server ($ this ->socket );
114+ $ server ->on ('request ' , function (Request $ request ) use ($ once ) {
115+ $ request ->on ('data ' , $ once );
116+ });
117+
118+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
119+
120+ $ data = '' ;
121+ $ data .= "POST / HTTP/1.1 \r\n" ;
122+ $ data .= "Content-Length: 100 \r\n" ;
123+ $ data .= "\r\n" ;
124+ $ data .= "incomplete " ;
125+ $ this ->connection ->emit ('data ' , array ($ data ));
126+ }
127+
128+ public function testRequestEventWithPartialBodyWillEmitData ()
129+ {
130+ $ once = $ this ->expectCallableOnceWith ('incomplete ' );
131+
132+ $ server = new Server ($ this ->socket );
133+ $ server ->on ('request ' , function (Request $ request ) use ($ once ) {
134+ $ request ->on ('data ' , $ once );
135+ });
136+
137+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
138+
139+ $ data = '' ;
140+ $ data .= "POST / HTTP/1.1 \r\n" ;
141+ $ data .= "Content-Length: 100 \r\n" ;
142+ $ data .= "\r\n" ;
143+ $ this ->connection ->emit ('data ' , array ($ data ));
144+
145+ $ data = '' ;
146+ $ data .= "incomplete " ;
147+ $ this ->connection ->emit ('data ' , array ($ data ));
148+ }
149+
82150 public function testResponseContainsPoweredByHeader ()
83151 {
84152 $ server = new Server ($ this ->socket );
0 commit comments