Created
February 16, 2016 09:29
-
-
Save lucasmichot/db42a79854ffe8575443 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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