php - Symfony2 return CrossDomain header on every response -
php - Symfony2 return CrossDomain header on every response -
is there way configure app homecoming specific header every response?
i'm developing restful api , need back upwards cross domain requests, i've been looking @ cors needs me homecoming header on every response:
access-control-allow-credentials' true access-control-allow-origin' any client access-control-allow-methods 'get,put,post,delete,options' access-control-allow-headers, 'x-csrf-token, x-requested-with, accept, accept-version, - - content-length, content-md5, content-type, date, x-api-version'
you can create custom responselistener
, set header each response:
namespace acme\demobundle\eventlistener; utilize symfony\component\httpkernel\event\filterresponseevent; class responselistener { public function onkernelresponse(filterresponseevent $event) { $request = $event->getrequest(); // on situations if (false === strpos($request->headers->get('foobar'), 'barfoo')) { return; } // set custom header of response $event->getresponse()->headers->set('acme', 'demo'); } }
then declare listener service:
# app/config/config.yml services: kernel.listener.your_listener_name: class: acme\demobundle\eventlistener\responselistener tags: - { name: kernel.event_listener, event: kernel.response, method: onkernelresponse }
http://symfony.com/doc/current/cookbook/service_container/event_listener.html
php symfony2 cross-domain cors
Comments
Post a Comment