@@ -75,4 +75,45 @@ private function createGetRequest()
7575
7676 return $ data ;
7777 }
78+
79+ public function testServerRespondsToExpectContinue ()
80+ {
81+ $ io = new ServerStub ();
82+ $ server = new Server ($ io );
83+ $ conn = new ConnectionStub ();
84+ $ io ->emit ('connection ' , array ($ conn ));
85+
86+ $ requestReceived = false ;
87+ $ postBody = '{"React":true} ' ;
88+ $ httpRequestText = $ this ->createPostRequestWithExpect ($ postBody );
89+
90+ $ conn ->emit ('data ' , array ($ httpRequestText ));
91+
92+ $ server ->on ('request ' , function ($ request , $ _ ) use (&$ requestReceived , $ postBody ) {
93+ $ requestReceived = true ;
94+ $ this ->assertEquals ($ postBody , $ request ->getBody ());
95+ });
96+
97+ // If server received Expect: 100-continue - the client won't send the body right away
98+ $ this ->assertEquals (false , $ requestReceived );
99+
100+ $ this ->assertEquals ("HTTP/1.1 100 Continue \r\n\r\n" , $ conn ->getData ());
101+
102+ $ conn ->emit ('data ' , array ($ postBody ));
103+
104+ $ this ->assertEquals (true , $ requestReceived );
105+
106+ }
107+
108+ private function createPostRequestWithExpect ($ postBody )
109+ {
110+ $ data = "POST / HTTP/1.1 \r\n" ;
111+ $ data .= "Host: example.com:80 \r\n" ;
112+ $ data .= "Content-Type: application/json \r\n" ;
113+ $ data .= "Content-Length: " . strlen ($ postBody ) . "\r\n" ;
114+ $ data .= "Expect: 100-continue \r\n" ;
115+ $ data .= "\r\n" ;
116+
117+ return $ data ;
118+ }
78119}
0 commit comments