Skip to content

Commit

Permalink
Clean up the x-clockwork cookie if it's not needed anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsgoingd committed Oct 27, 2024
1 parent d55e7d5 commit 4184f0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Clockwork/Support/Laravel/ClockworkSupport.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ public function processRequest($request, $response)
$response->cookie(
new Cookie('x-clockwork', json_encode($clockworkBrowser), time() + 60, null, null, $request->secure(), false)
);
} elseif (in_array('x-clockwork', $this->incomingRequest()->cookies)) {
$response->cookie(
new Cookie('x-clockwork', '', -1, null, null, $request->secure(), false)
);
}

return $response;
Expand Down
4 changes: 4 additions & 0 deletions Clockwork/Support/Vanilla/Clockwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ public function sendHeaders()

if ($this->config['features']['performance']['client_metrics'] || $this->config['toolbar']) {
$this->setCookie('x-clockwork', $this->getCookiePayload(), time() + 60);
} elseif (in_array('x-clockwork', $this->incomingRequest()->cookies)) {
$this->setCookie('x-clockwork', '', -1);
}
}

Expand Down Expand Up @@ -487,6 +489,7 @@ protected function incomingRequestFromGlobals()
'uri' => $_SERVER['REQUEST_URI'],
'headers' => $_SERVER,
'input' => array_merge($_GET, $_POST, (array) json_decode(file_get_contents('php://input'), true)),
'cookies' => $_COOKIE,
'host' => explode(':', $_SERVER['HTTP_HOST'] ?: $_SERVER['SERVER_NAME'] ?: $_SERVER['SERVER_ADDR'])[0]
]);
}
Expand All @@ -503,6 +506,7 @@ protected function incomingRequestFromPsr()
(array) $this->psrRequest->getParsedBody(),
(array) json_decode((string) $this->psrRequest->getBody(), true)
),
'cookies' => $this->psrRequest->getCookieParams(),
'host' => $this->psrRequest->getUri()->getHost()
]);
}
Expand Down

0 comments on commit 4184f0a

Please sign in to comment.