@@ -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 );
@@ -107,6 +119,62 @@ public function testRequestResumeWillbeForwardedToConnection()
107119 $ this ->connection ->emit ('data ' , array ($ data ));
108120 }
109121
122+ public function testRequestEventWithoutBodyWillNotEmitData ()
123+ {
124+ $ never = $ this ->expectCallableNever ();
125+
126+ $ server = new Server ($ this ->socket );
127+ $ server ->on ('request ' , function (Request $ request ) use ($ never ) {
128+ $ request ->on ('data ' , $ never );
129+ });
130+
131+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
132+
133+ $ data = $ this ->createGetRequest ();
134+ $ this ->connection ->emit ('data ' , array ($ data ));
135+ }
136+
137+ public function testRequestEventWithSecondDataEventWillEmitBodyData ()
138+ {
139+ $ once = $ this ->expectCallableOnceWith ('incomplete ' );
140+
141+ $ server = new Server ($ this ->socket );
142+ $ server ->on ('request ' , function (Request $ request ) use ($ once ) {
143+ $ request ->on ('data ' , $ once );
144+ });
145+
146+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
147+
148+ $ data = '' ;
149+ $ data .= "POST / HTTP/1.1 \r\n" ;
150+ $ data .= "Content-Length: 100 \r\n" ;
151+ $ data .= "\r\n" ;
152+ $ data .= "incomplete " ;
153+ $ this ->connection ->emit ('data ' , array ($ data ));
154+ }
155+
156+ public function testRequestEventWithPartialBodyWillEmitData ()
157+ {
158+ $ once = $ this ->expectCallableOnceWith ('incomplete ' );
159+
160+ $ server = new Server ($ this ->socket );
161+ $ server ->on ('request ' , function (Request $ request ) use ($ once ) {
162+ $ request ->on ('data ' , $ once );
163+ });
164+
165+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
166+
167+ $ data = '' ;
168+ $ data .= "POST / HTTP/1.1 \r\n" ;
169+ $ data .= "Content-Length: 100 \r\n" ;
170+ $ data .= "\r\n" ;
171+ $ this ->connection ->emit ('data ' , array ($ data ));
172+
173+ $ data = '' ;
174+ $ data .= "incomplete " ;
175+ $ this ->connection ->emit ('data ' , array ($ data ));
176+ }
177+
110178 public function testResponseContainsPoweredByHeader ()
111179 {
112180 $ server = new Server ($ this ->socket );
0 commit comments