Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3661'
Browse files Browse the repository at this point in the history
Close #3661
  • Loading branch information
weierophinney committed Feb 5, 2013
2 parents 9d1e9ad + 4035aa8 commit 53adce5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions library/Zend/Mvc/ResponseSender/AbstractResponseSender.php
Expand Up @@ -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) {
Expand All @@ -37,6 +35,9 @@ public function sendHeaders(SendResponseEvent $event)
header($header->toString());
}

$status = $response->renderStatusLine();
header($status);

$event->setHeadersSent();
return $this;
}
Expand Down
31 changes: 31 additions & 0 deletions tests/ZendTest/Mvc/ResponseSender/AbstractResponseSenderTest.php
Expand Up @@ -11,6 +11,7 @@
namespace ZendTest\Mvc\ResponseSender;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Http\Headers;
use Zend\Http\Response;

/**
Expand Down Expand Up @@ -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'
);
}
}

0 comments on commit 53adce5

Please sign in to comment.