Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/fantasticjamieburns/zf2 int…

…o hotfix/3661
  • Loading branch information...
commit 1945680354dbe630e297f5a714cd3e9074ca812c 2 parents ed5dbf1 + 876f95d
@weierophinney weierophinney authored
View
5 library/Zend/Mvc/ResponseSender/AbstractResponseSender.php
@@ -26,8 +26,6 @@ public function sendHeaders(SendResponseEvent $event)
}
$response = $event->getResponse();
- $status = $response->renderStatusLine();
- header($status);
foreach ($response->getHeaders() as $header) {
if ($header instanceof MultipleHeaderInterface) {
@@ -37,6 +35,9 @@ public function sendHeaders(SendResponseEvent $event)
header($header->toString());
}
+ $status = $response->renderStatusLine();
+ header($status);
+
$event->setHeadersSent();
return $this;
}
View
31 tests/ZendTest/Mvc/ResponseSender/AbstractResponseSenderTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Mvc\ResponseSender;
use PHPUnit_Framework_TestCase as TestCase;
+use Zend\Http\Headers;
use Zend\Http\Response;
/**
@@ -53,4 +54,34 @@ public function testSendHeadersTwoTimesSendsOnlyOnce()
$responseSender->sendHeaders($mockSendResponseEvent);
$this->assertEquals(array(), xdebug_get_headers());
}
+
+ /**
+ * @runInSeparateProcess
+ */
+ public function testSendHeadersSendsStatusLast()
+ {
+ if (!function_exists('xdebug_get_headers')) {
+ $this->markTestSkipped('Xdebug extension needed, skipped test');
+ }
+
+ $mockResponse = $this->getMock('Zend\Http\Response');
+ $mockResponse->expects($this->once())->method('getHeaders')->will($this->returnValue(Headers::fromString('Location: example.com')));
+ $mockResponse->expects($this->once())->method('renderStatusLine')->will($this->returnValue('X-Test: HTTP/1.1 202 Accepted'));
+
+ $mockSendResponseEvent = $this->getMock('Zend\Mvc\ResponseSender\SendResponseEvent', array('getResponse'));
+ $mockSendResponseEvent->expects($this->any())->method('getResponse')->will($this->returnValue($mockResponse));
+
+ $responseSender = $this->getMockForAbstractClass('Zend\Mvc\ResponseSender\AbstractResponseSender');
+ $responseSender->sendHeaders($mockSendResponseEvent);
+
+ $sentHeaders = xdebug_get_headers();
+
+ $this->assertCount(2, $sentHeaders);
+ $this->assertEquals('Location: example.com', $sentHeaders[0]);
+ $this->assertEquals(
+ 'X-Test: HTTP/1.1 202 Accepted',
+ $sentHeaders[1],
+ 'Status header is sent last to prevent header() from overwriting the ZF status code when a Location header is used'
+ );
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.