Skip to content

Commit

Permalink
Fix listener
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaguerre committed Jun 5, 2016
1 parent fd08c1b commit cf3f5e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## RobotsBundle

Add contextual robot meta headers.
No need for robots.txt files,
add contextual robot meta headers.

### Installation

Expand All @@ -20,5 +21,4 @@ dag_robots:
### TODO
- [ ] Add route to serve robots.txt files dynamically.
- [ ] Add tests
13 changes: 9 additions & 4 deletions RobotsBundle/EventListener/KernelResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class KernelResponseListener
*/
protected $tagResolver;

/**
* @var bool
*/
protected $cloak = false;

/**
* @param RequestCheckerInterface $requestChecker
* @param TagResolverInterface $tagResolver
Expand All @@ -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));
}
}
}

0 comments on commit cf3f5e1

Please sign in to comment.