Exemple #1
0
 /**
  * @return FirewallInterface
  */
 public function getFirewall()
 {
     if (!$this->firewall) {
         $this->firewall = new DefaultFirewall();
         $this->firewall->setLogger($this->getLogger());
     }
     return $this->firewall;
 }
 /**
  * Filter and mark incoming requests
  *
  * @priority high
  *
  * @param ProxyRequestEvent $event
  */
 public function onProxyRequest(ProxyRequestEvent $event)
 {
     if (!$event->isCancelled() && !$event->hasResponse()) {
         $response = null;
         $request = $event->getRequest();
         $config = $event->getProxy()->getConfig();
         if ($this->isSelfRequest($request, $config)) {
             $event->setIsCancelled();
             $event->getLogger()->warning(sprintf('Proxy server made a call to itself that cannot be handled, request will be cancelled'));
         } elseif (in_array($request->getHost(), $config->getHostsOnPort($request->getPort()))) {
             // display proxy welcome page as it is a direct hit
             $response = new Response($this->getResource('home.html', $event->getProxy()), 200);
         } elseif (!$this->firewall->isAllowed($request)) {
             $event->setIsCancelled();
             $event->getLogger()->debug(sprintf('Request was cancelled as it was not allowed by a firewall'));
         }
         if ($response) {
             $event->setResponse($response);
         }
     }
 }