Skip to content

Instantly share code, notes, and snippets.

@lucasmichot
Created February 16, 2016 09:29
Show Gist options
  • Save lucasmichot/db42a79854ffe8575443 to your computer and use it in GitHub Desktop.
Save lucasmichot/db42a79854ffe8575443 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Routing\Middleware\ThrottleRequests as BaseThrottleRequests;
class ThrottleRequests extends BaseThrottleRequests
{
/**
* Add the limit header information to the given response.
*
* @param \Symfony\Component\HttpFoundation\Response $response
* @param int $maxAttempts
* @param int $remainingAttempts
* @param int|null $retryAfter
* @return \Illuminate\Http\Response
*/
protected function addHeaders(Response $response, $maxAttempts, $remainingAttempts, $retryAfter = null)
{
$headers = [
'X-RateLimit-Limit' => $maxAttempts,
'X-RateLimit-Remaining' => $remainingAttempts,
];
if (! is_null($retryAfter)) {
$headers['Retry-After'] = $retryAfter;
}
$response->headers->add($headers);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment