| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/switchyard/current/app/Http/Middleware/ |
Upload File : |
<?php
namespace App\Http\Middleware;
use App\Http\Responses\ProblemResponse;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Symfony\Component\HttpFoundation\Response;
/**
* Per-IP rate limit for the public demo endpoints. Default: 50 ops / hour.
*/
class DemoRateLimit
{
public function handle(Request $request, Closure $next): Response
{
$limit = (int) config('switchyard.demo.rate_limit_per_hour', 50);
$key = 'demo:'.($request->ip() ?? 'anon');
if (RateLimiter::tooManyAttempts($key, $limit)) {
$retryAfter = RateLimiter::availableIn($key);
return new ProblemResponse(
status: 429,
title: 'Too many requests',
detail: "Demo rate limit of {$limit} requests per hour exceeded. Retry in {$retryAfter} seconds.",
);
}
RateLimiter::hit($key, 3600);
return $next($request);
}
}