diff --git a/README.md b/README.md index 929b6d7..c6954a0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ## RobotsBundle -Add contextual robot meta headers. +No need for robots.txt files, +add contextual robot meta headers. ### Installation @@ -20,5 +21,4 @@ dag_robots: ### TODO -- [ ] Add route to serve robots.txt files dynamically. - [ ] Add tests \ No newline at end of file diff --git a/RobotsBundle/EventListener/KernelResponseListener.php b/RobotsBundle/EventListener/KernelResponseListener.php index 83dfb14..dbc4a89 100644 --- a/RobotsBundle/EventListener/KernelResponseListener.php +++ b/RobotsBundle/EventListener/KernelResponseListener.php @@ -18,6 +18,11 @@ class KernelResponseListener */ protected $tagResolver; + /** + * @var bool + */ + protected $cloak = false; + /** * @param RequestCheckerInterface $requestChecker * @param TagResolverInterface $tagResolver @@ -39,12 +44,12 @@ public function addRobotTags(FilterResponseEvent $event) return; } - // if (!$this->requestChecker->isCrawler($event->getRequest())) { - // return; - // } + if ($this->cloak && !$this->requestChecker->isCrawler($event->getRequest())) { + return; + } if ($tags = $this->tagResolver->resolve($event->getRequest())) { - $event->getResponse()->headers->set('X-Robots-Tag', $tags); + $event->getResponse()->headers->set('X-Robots-Tag', implode(', ', $tags)); } } }