use Illuminate\Foundation\Testing\WithoutMiddleware;
class ExampleTestClass extends TestCase
{
use WithoutMiddleware;
public function exampleTestMethod()
{
$this->withoutMiddleware();
// your test
}
}
Nov 6, 2019
5
Level 1
How to disable throttle or rate limiter ?
Hi. I need help from you guys. I want to disable rate limiter because I want to make some load test, and I already make comment on Kernel.php:
'api' => [
// 'throttle:120,1',
'bindings',
],
but my load test still have response 429 from ThrottleRequests class. What should I do next? Thanks.
Level 1
When there is pressure is up, the solution will come in any way. This is my solution so far:
-1. Create new entry in app.php:
'app_config' => json_decode(env("APP_CONFIG", "{}"), TRUE),
-2. Create new middleware base on ThrottleRequests, name it as you like, mine is like this:
namespace App\Http\Middleware;
use Illuminate\Routing\Middleware\ThrottleRequests;
use Closure;
class NoThrottle extends ThrottleRequests
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param int|string $maxAttempts
* @param float|int $decayMinutes
* @return mixed
* @throws \Illuminate\Http\Exceptions\ThrottleRequestsException
*/
public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes = 1)
{
if (config("app.app_config")["nothrottle"] ?? false) {
$response = $next($request);
return $this->addHeaders(
$response, $maxAttempts,
$maxAttempts
);
}
return parent::handle($request, $next, $maxAttempts, $decayMinutes);
}
}
-3. Update $routeMiddleware inside Kernel.php:
//'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'throttle' => \App\Http\Middleware\NoThrottle::class,
Usage: To disable throttle, add new entry in .env:
APP_CONFIG={"nothrottle":true}
This solution is now enough for me to do some load test, I hope someone wants to improve it.
Please or to participate in this conversation.