示例#1
0
 /**
  * Attach the after filter to adjust the response.
  *
  * @return void
  */
 protected function attachAfterFilter()
 {
     $this->router->after(function (Request $request, Response $response) {
         $response->headers->set('X-RateLimit-Limit', $this->limiter->getThrottle()->getLimit());
         $response->headers->set('X-RateLimit-Remaining', $this->limiter->getRemainingLimit());
         $response->headers->set('X-RateLimit-Reset', $this->limiter->getRateLimitReset());
     });
 }
示例#2
0
 /**
  * Register the API rate limiter.
  *
  * @return void
  */
 protected function registerRateLimiter()
 {
     $this->app->bindShared('api.limiter', function ($app) {
         $throttles = $this->prepareConfigInstances($app['config']['api::throttling']);
         $limiter = new RateLimiter($app, $app['cache'], $throttles);
         $limiter->setRateLimiter(function ($container, $request) {
             return $request->getClientIp();
         });
         return $limiter;
     });
 }