Skip to content

Commit 8b95389

Browse files
committed
feat: add disabled environments to rate limit config options
1 parent 1457e19 commit 8b95389

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

config/image-transform-url.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@
7777

7878
'rate_limit' => [
7979
'enabled' => env('IMAGE_TRANSFORM_RATE_LIMIT_ENABLED', true),
80+
'disabled_for_environments' => [
81+
'local',
82+
'testing',
83+
],
8084
'max_attempts' => env('IMAGE_TRANSFORM_RATE_LIMIT_MAX_REQUESTS', 2),
8185
'decay_seconds' => env('IMAGE_TRANSFORM_RATE_LIMIT_DECAY_SECONDS', 60),
8286
],

src/Http/Controllers/ImageTransformerController.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Http\Request;
1111
use Illuminate\Http\Response;
1212
use Illuminate\Support\Arr;
13+
use Illuminate\Support\Facades\App;
1314
use Illuminate\Support\Facades\Cache;
1415
use Illuminate\Support\Facades\File;
1516
use Illuminate\Support\Facades\RateLimiter;
@@ -56,7 +57,9 @@ public function __invoke(Request $request, string $options, string $path)
5657
}
5758
}
5859

59-
if (config()->boolean('image-transform-url.rate_limit.enabled')) {
60+
if (
61+
config()->boolean('image-transform-url.rate_limit.enabled') &&
62+
! in_array(App::environment(), config()->array('image-transform-url.rate_limit.disabled_for_environments'))) {
6063
$this->rateLimit($request, $path);
6164
}
6265

tests/Feature/RateLimitTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
it('can apply rate limiting to image transformation requests with distinct options', function () {
1313
// Set up the rate limit configuration
1414
config()->set('image-transform-url.rate_limit.enabled', true);
15+
// Enable for this test by not setting 'testing' in the disabled_for_environments array
16+
config()->set('image-transform-url.rate_limit.disabled_for_environments', [
17+
'local',
18+
]);
1519
config()->set('image-transform-url.rate_limit.max_attempts', 2);
1620
config()->set('image-transform-url.rate_limit.decay_seconds', 60);
1721

0 commit comments

Comments
 (0)