@@ -1362,6 +1362,70 @@ function ($data) use (&$buffer) {
13621362 $ this ->assertNotContainsString ("\r\nContent-Length: 3 \r\n" , $ buffer );
13631363 }
13641364
1365+ public function testResponseContainsNoContentLengthHeaderForNotModifiedStatus ()
1366+ {
1367+ $ server = new StreamingServer (Factory::create (), function (ServerRequestInterface $ request ) {
1368+ return new Response (
1369+ 304 ,
1370+ array (),
1371+ ''
1372+ );
1373+ });
1374+
1375+ $ buffer = '' ;
1376+ $ this ->connection
1377+ ->expects ($ this ->any ())
1378+ ->method ('write ' )
1379+ ->will (
1380+ $ this ->returnCallback (
1381+ function ($ data ) use (&$ buffer ) {
1382+ $ buffer .= $ data ;
1383+ }
1384+ )
1385+ );
1386+
1387+ $ server ->listen ($ this ->socket );
1388+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
1389+
1390+ $ data = "GET / HTTP/1.1 \r\nHost: localhost \r\n\r\n" ;
1391+ $ this ->connection ->emit ('data ' , array ($ data ));
1392+
1393+ $ this ->assertContainsString ("HTTP/1.1 304 Not Modified \r\n" , $ buffer );
1394+ $ this ->assertNotContainsString ("\r\nContent-Length: 0 \r\n" , $ buffer );
1395+ }
1396+
1397+ public function testResponseContainsExplicitContentLengthHeaderForNotModifiedStatus ()
1398+ {
1399+ $ server = new StreamingServer (Factory::create (), function (ServerRequestInterface $ request ) {
1400+ return new Response (
1401+ 304 ,
1402+ array ('Content-Length ' => 3 ),
1403+ ''
1404+ );
1405+ });
1406+
1407+ $ buffer = '' ;
1408+ $ this ->connection
1409+ ->expects ($ this ->any ())
1410+ ->method ('write ' )
1411+ ->will (
1412+ $ this ->returnCallback (
1413+ function ($ data ) use (&$ buffer ) {
1414+ $ buffer .= $ data ;
1415+ }
1416+ )
1417+ );
1418+
1419+ $ server ->listen ($ this ->socket );
1420+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
1421+
1422+ $ data = "GET / HTTP/1.1 \r\nHost: localhost \r\n\r\n" ;
1423+ $ this ->connection ->emit ('data ' , array ($ data ));
1424+
1425+ $ this ->assertContainsString ("HTTP/1.1 304 Not Modified \r\n" , $ buffer );
1426+ $ this ->assertContainsString ("\r\nContent-Length: 3 \r\n" , $ buffer );
1427+ }
1428+
13651429 public function testResponseContainsNoResponseBodyForNotModifiedStatus ()
13661430 {
13671431 $ server = new StreamingServer (Factory::create (), function (ServerRequestInterface $ request ) {
0 commit comments