Perform rate limiting before a request is executed.

@param \Dingo\Api\Http\Request $request
@param \Closure                $next

@throws \Symfony\Component\HttpKernel\Exception\HttpException

@return mixed
763078
public function handle($request, Closure $next)
    {
        if ($request instanceof InternalRequest) {
            return $next($request);
        }

        $route = $this->router->getCurrentRoute();

        if ($route->hasThrottle()) {
            $this->handler->setThrottle($route->getThrottle());
        }

        $this->handler->rateLimitRequest($request, $route->getRateLimit(), $route->getRateLimitExpiration());

        if ($this->handler->exceededRateLimit()) {
            throw new RateLimitExceededException('You have exceeded your rate limit.', null, $this->getHeaders());
        }

        $response = $next($request);

        if ($this->handler->requestWasRateLimited()) {
            return $this->responseWithHeaders($response);
        }

        return $response;
    }
1135625
public function handle($request, Closure $next)
    {
        if (! $this->auth->user()->managesUsers()) {
            return response('Unauthorized.', 401);
        }

        return $next($request);
    }
462069
public function handle($request, Closure $next)
    {
        $token = $this->getTokenFromRequest($request);
        $this->jwt->setToken($token)->validateOrFail();

        return $next($request);
    }
1296736
public function handle($request, Closure $next)
    {
        try {
            $response = $next($request);

            // Was an exception thrown? If so and available catch in our middleware
            if (isset($response->exception) && $response->exception) {
                throw $response->exception;
            }

            return $response;
        } catch (OAuthException $e) {
            $message = env('API_DEBUG') ? $e->getMessage() : null;
            throw new HttpException($e->httpStatusCode, $message, $e, $e->getHttpHeaders());
        } catch (HttpResponseException $e) {
            $message = env('API_DEBUG') ? $e->getMessage() : null;
            throw new HttpException($e->getResponse()->getStatusCode(), $message, $e);
        } catch (AuthenticationException $e) {
            throw new UnauthorizedHttpException(null, $e->getMessage(), $e);
        } catch (ValidatorException $e) {
            $messageBag = $e->getMessageBag();
            throw new ResourceException($messageBag->first(), $messageBag->all());
        } catch (ModelNotFoundException $e) {
            throw new NotFoundHttpException('No results found.');
        }
    }
1082528
public function handle($request, Closure $next)
    {
        $this->aclPolicy->defineAbilities();

        if ( ! $this->aclPolicy->passesAuthorization() ) {
            abort(403, config('acl.unauthorized_message'));
        }

        return $next($request);
    }
491073
public function handle($request, Closure $next)
    {
        $request->setTrustedProxies(['127.0.0.1', $request->server->get('REMOTE_ADDR')]);

        return $next($request);
    }
41077
public function handle($request, Closure $next)
    {
        config(['request.timezone' => $this->determineRequestTimezone($request)]);

        return $next($request);
    }
209437
public function handle($request, Closure $next)
    {

        if ($request->session()->has('language')) {
            $local = $request->session()->get('language', config('app.locale'));
            app()->setLocale($local);
        }

        return $next($request);
    }
1302374
public function handle($request, Closure $next)
    {
        $reauth = new ReauthLimiter($request);

        if (!$reauth->check()) {
            $request->session()->put('url.intended', $request->url());

            return $this->invalidated($request);
        }

        return $next($request);
    }
1027237
public function handle($request, Closure $next)
    {
        $locale = $this->localizer->detect();

        if ($locale) {
            $this->localizer->store($locale);
        }

        return $next($request);
    }
68290
public function handle(Request $request, Closure $next)
    {
        // If the request URL is ignored from localization.
        if ($this->shouldIgnore($request)) return $next($request);

        $segment = $request->segment(1, null);
        $locale  = session('locale', null);

        if ($this->localization->isLocaleSupported($segment)) {
            session()->put(['locale' => $segment]);

            return $next($request);
        }
        elseif ($this->localization->isDefaultLocaleHiddenInUrl()) {
            $locale = $this->localization->getDefaultLocale();
            session()->put(compact('locale'));
        }

        if (is_string($locale) && ! $this->isDefaultLocaleHidden($locale)) {
            session()->reflash();

            if ( ! is_null($redirect = $this->getLocalizedRedirect($locale)))
                return $redirect;
        }

        return $next($request);
    }
888282
public function handle($request, Closure $next)
    {
        if ($class = AdminManager::getAdminInstance()) {
            $class = get_class($class);
        }

        if (!$this->permissions->check($class)) {
            return $this->permissions->denied($class);
        }

        return $next($request);
    }
987842
public function handle(Request $request, Closure $next)
    {
        $request::setTrustedProxies([], $this->getTrustedHeaderNames()); // Reset trusted proxies between requests
        $this->setTrustedProxyIpAddresses($request);

        return $next($request);
    }
812246
public function handle($request, Closure $next)
    {
        if (! Current::port()) {
            return $next($request);
        }

        $uri = ltrim(Current::requestPath(), '/');

        if (starts_with($uri, 'sv/res/')) {
            ResourceActivityEvent::dispatch($request);
        }

        return $next($request);
    }
1001608
public function handle(Request $request, Closure $next)
    {
        $referer = $request->headers->get('referer');

        return $this->blocker->isBlocked($referer)
            ? $this->getBlockedResponse()
            : $next($request);
    }
1231658
public function handle($request, Closure $next)
    {
        $this->authorizer->setRequest($request);

        $this->authorizer->checkAuthCodeRequest();

        return $next($request);
    }
1197187
public function handle(Request $request, Closure $next)
    {
        $request::setTrustedProxies([$request->getClientIp()]);

        if (config('redirect.https', false) && !$request->secure())
        {
            return redirect()->secure($request->getRequestUri());
        }

        return $next($request);
    }