Skip to content

Commit cbdd61b

Browse files
feat: add shouldIgnoreHosts method to filter HTTP client requests by host (#1650)
* feat: add shouldIgnoreHosts method to filter HTTP client requests by host * style: fix coding style * refactor: add 'enabled' flag for ClientRequestWatcher configuration * Update ClientRequestWatcher.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 4fda9e6 commit cbdd61b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

config/telescope.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,10 @@
143143
'ignore' => [],
144144
],
145145

146-
Watchers\ClientRequestWatcher::class => env('TELESCOPE_CLIENT_REQUEST_WATCHER', true),
146+
Watchers\ClientRequestWatcher::class => [
147+
'enabled' => env('TELESCOPE_CLIENT_REQUEST_WATCHER', true),
148+
'ignore_hosts' => [],
149+
],
147150

148151
Watchers\CommandWatcher::class => [
149152
'enabled' => env('TELESCOPE_COMMAND_WATCHER', true),

src/Watchers/ClientRequestWatcher.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public function recordFailedRequest(ConnectionFailed $event)
5757
*/
5858
public function recordResponse(ResponseReceived $event)
5959
{
60-
if (! Telescope::isRecording()) {
60+
if (! Telescope::isRecording() ||
61+
$this->shouldIgnoreHost($event)) {
6162
return;
6263
}
6364

@@ -76,6 +77,19 @@ public function recordResponse(ResponseReceived $event)
7677
);
7778
}
7879

80+
/**
81+
* Determine whether to ignore this request based on its host.
82+
*
83+
* @param mixed $event
84+
* @return bool
85+
*/
86+
protected function shouldIgnoreHost($event)
87+
{
88+
$host = $event->request->toPsrRequest()->getUri()->getHost();
89+
90+
return in_array($host, Arr::get($this->options, 'ignore_hosts', []));
91+
}
92+
7993
/**
8094
* Determine if the content is within the set limits.
8195
*

0 commit comments

Comments
 (0)