@@ -1291,6 +1291,70 @@ function ($data) use (&$buffer) {
12911291 $ this ->assertNotContainsString ("bye " , $ buffer );
12921292 }
12931293
1294+ public function testResponseContainsNoContentLengthHeaderForNotModifiedStatus ()
1295+ {
1296+ $ server = new StreamingServer (Factory::create (), function (ServerRequestInterface $ request ) {
1297+ return new Response (
1298+ 304 ,
1299+ array (),
1300+ ''
1301+ );
1302+ });
1303+
1304+ $ buffer = '' ;
1305+ $ this ->connection
1306+ ->expects ($ this ->any ())
1307+ ->method ('write ' )
1308+ ->will (
1309+ $ this ->returnCallback (
1310+ function ($ data ) use (&$ buffer ) {
1311+ $ buffer .= $ data ;
1312+ }
1313+ )
1314+ );
1315+
1316+ $ server ->listen ($ this ->socket );
1317+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
1318+
1319+ $ data = "GET / HTTP/1.1 \r\nHost: localhost \r\n\r\n" ;
1320+ $ this ->connection ->emit ('data ' , array ($ data ));
1321+
1322+ $ this ->assertContainsString ("HTTP/1.1 304 Not Modified \r\n" , $ buffer );
1323+ $ this ->assertNotContainsString ("\r\nContent-Length: 0 \r\n" , $ buffer );
1324+ }
1325+
1326+ public function testResponseContainsExplicitContentLengthHeaderForNotModifiedStatus ()
1327+ {
1328+ $ server = new StreamingServer (Factory::create (), function (ServerRequestInterface $ request ) {
1329+ return new Response (
1330+ 304 ,
1331+ array ('Content-Length ' => 3 ),
1332+ ''
1333+ );
1334+ });
1335+
1336+ $ buffer = '' ;
1337+ $ this ->connection
1338+ ->expects ($ this ->any ())
1339+ ->method ('write ' )
1340+ ->will (
1341+ $ this ->returnCallback (
1342+ function ($ data ) use (&$ buffer ) {
1343+ $ buffer .= $ data ;
1344+ }
1345+ )
1346+ );
1347+
1348+ $ server ->listen ($ this ->socket );
1349+ $ this ->socket ->emit ('connection ' , array ($ this ->connection ));
1350+
1351+ $ data = "GET / HTTP/1.1 \r\nHost: localhost \r\n\r\n" ;
1352+ $ this ->connection ->emit ('data ' , array ($ data ));
1353+
1354+ $ this ->assertContainsString ("HTTP/1.1 304 Not Modified \r\n" , $ buffer );
1355+ $ this ->assertContainsString ("\r\nContent-Length: 3 \r\n" , $ buffer );
1356+ }
1357+
12941358 public function testResponseContainsNoResponseBodyForNotModifiedStatus ()
12951359 {
12961360 $ server = new StreamingServer (Factory::create (), function (ServerRequestInterface $ request ) {
0 commit comments