Skip to content

Commit d1adffa

Browse files
Fix bug causing the middleware to never work (#25)
Before this change, the middleware would consider a request as "requesting pre-rendered page" only when the user agent was exactly the same as one of the "crawler user agents" specified in the config file. This is a bug because, typically, the User Agent of a crawler is not just one word. Example of one of the Googlebot's User Agents: Googlebot/2.1 (+http://www.google.com/bot.html)
1 parent a324b25 commit d1adffa

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/PrerenderMiddleware.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ private function shouldShowPrerenderedPage(Request $request): bool
142142
}
143143

144144
// prerender if a crawler is detected
145-
if (in_array(strtolower($userAgent), $this->crawlerUserAgents)) {
146-
$isRequestingPrerenderedPage = true;
145+
foreach ($this->crawlerUserAgents as $crawlerUserAgent) {
146+
if (Str::contains($userAgent, strtolower($crawlerUserAgent))) {
147+
$isRequestingPrerenderedPage = true;
148+
}
147149
}
148150

149151
if ($bufferAgent) {

0 commit comments

Comments
 (0)