Commit 262fd9a0 authored by Fabien Potencier's avatar Fabien Potencier

added Symfony2 ResponseListener registration

parent a46df6a3
......@@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\EventListener\ResponseListener;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
......@@ -81,6 +82,7 @@ class Application extends \Pimple implements HttpKernelInterface, EventSubscribe
if (isset($app['exception_handler'])) {
$dispatcher->addSubscriber($app['exception_handler']);
}
$dispatcher->addListener(KernelEvents::RESPONSE, array(new ResponseListener($app['charset']), 'onKernelResponse'));
return $dispatcher;
});
......
......@@ -146,6 +146,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Hello Fabien', $app->handle(Request::create('/Fabien'))->getContent());
}
public function testHttpSpec()
{
$app = new Application();
$app['charset'] = 'ISO-8859-1';
$app->get('/', function () {
return 'hello';
});
// content is empty for HEAD requests
$response = $app->handle(Request::create('/', 'HEAD'));
$this->assertEquals('', $response->getContent());
// charset is appended to Content-Type
$response = $app->handle(Request::create('/'));
$response->prepare();
$this->assertEquals('text/html; charset=ISO-8859-1', $response->headers->get('Content-Type'));
}
}
class FooController
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment