Create a too many requests http exception.

@param string $key
@param int    $limit
@param bool   $headers

@return \AltThree\Throttle\ThrottlingException
3606
protected function buildException(string $key, int $limit, bool $headers)
    {
        $after = $this->limiter->availableIn($key);

        $exception = new ThrottlingException($after, 'Rate limit exceeded.');

        $headers = $this->getHeaders($key, $limit, $headers, $after, $exception->getHeaders());

        $exception->setHeaders($headers);

        return $exception;
    }
1287118
public function limit($limit, $offset = null)
    {
        if ($offset) {
            $this->getLimit()->setParams(array($limit, $offset));
        } else {
            $this->getLimit()->setParams(array($limit));
        }

        return $this;
    }
1016827
public function isRequestAllHeadersSupported(array $headers): bool
	{
		if (isset($this->settings[self::KEY_ALLOWED_HEADERS][self::VALUE_ALLOW_ALL_HEADERS])) {
			return true;
		}

		foreach ($headers as $header) {
			if (!isset($this->settings[self::KEY_ALLOWED_HEADERS][\strtolower($header)])) {
				return false;
			}
		}

		return true;
	}
1030477
public function handle(Request $request, Closure $next, $limit = null)
    {
        $response = $next($request);

        if ($response->isRedirection() || !$response instanceof Response || $request->isJson()) {
            return $response;
        }

        $this->generateAndAttachLinkHeaders($response, $limit);

        return $response;
    }
1229079
public function removeHeader($key)
    {
        if (isset($this->headers[$key])) {
            unset($this->headers[$key]);
        }
        return $this;
    }
877660
public function hmSet($key, $fields)
    {
        if ($this->hasMaxSize()) {
            foreach ($fields as $field => $value) {
                try {
                    if ($this->isLarge($value)) {
                        $fields[$field] = $this->setLargeValue($this->getMappedKey($key, $field), $value, 0, false);
                    }
                } catch (common_Exception $e) {
                    common_Logger::w('Max size value is misconfigured: ' . $e->getMessage());
                }
            }
        }

        return $this->getDriver()->hmSet($key, $fields);
    }
469961
public function request($path, $body, $httpMethod = 'GET', array $headers = [], array $options = [])
	{
		$request = $this->createRequest($httpMethod, $path, $body, $headers);

		try {
			$response = $this->client->send($request, $options);
		} catch (\LogicException $e) {
			throw new \ErrorException($e->getMessage(), $e->getCode(), $e);
		} catch (\RuntimeException $e) {
			throw new \RuntimeException($e->getMessage(), $e->getCode(), $e);
		}

		$this->lastRequest  = $request;
		$this->lastResponse = $response;

		return $response;
	}
51834
function handleRatelimit(?int $limit, ?int $remaining, ?float $resetTime) {
        if($limit === null && $remaining === null && $resetTime === null) {
            $this->remaining++; // there is no ratelimit...
            return;
        }
        
        $this->limit = $limit ?? $this->limit;
        $this->remaining = $remaining ?? $this->remaining;
        $this->resetTime = $resetTime ?? $this->resetTime;
        
        if($this->remaining === 0 && $this->resetTime > \microtime(true)) {
            $this->api->client->emit('debug', 'Endpoint "'.$this->endpoint.'" ratelimit encountered, continueing in '.($this->resetTime - \microtime(true)).' seconds');
        }
    }
315664
protected function buildResponse($key, $maxAttempts)
    {
        $response = new Response('Too Many Attempts.', 429);

        $retryAfter = $this->limiter->availableIn($key);

        return $this->addHeaders(
            $response, $maxAttempts,
            $this->calculateRemainingAttempts($key, $maxAttempts, $retryAfter),
            $retryAfter
        );
    }
1147256
private function doRequest($path, $headers = [])
    {
        if (!$this->isAvailable()) {
            throw new NotAvailableException('Service not available.');
        }

        if ($this->loadBalance !== null) {
            $uri = $this->loadBalance->getUri($this->serviceName);
            $this->zendClient->setUri($uri);
        }
        if ($this->appendPath && strlen($path) > 0 && $this->zendClient->getUri()->getPath() != '/') {
            $path = $this->zendClient->getUri()->getPath() . $path;
        }
        $this->zendClient->getUri()->setPath($path);

        $this->zendClient->getRequest()->getHeaders()->addHeaders($headers);

        if (!$this->zendClient->getRequest()->getHeaders()->has('X-Request-Id')) {
            $this->addRequestId();
        }

        $this->addRequestName($this->serviceName);

        $this->getEventManager()->trigger('request.pre', $this);

        $this->responseTime = 0;

        try {
            $requestTime = microtime(true);

            $zendHttpResponse = $this->zendClient->send();

            $this->responseTime = (float) sprintf('%.2f', (microtime(true) - $requestTime) * 1000);

            $this->addRequestTime($this->responseTime);

            $response = new Response($this->zendClient, $zendHttpResponse, $this->depth);
            $this->reportSuccess();
        } catch (RuntimeException $ex) {
            $this->reportFailure();
            $this->getEventManager()->trigger('request.fail', $this, $ex);
            throw new RuntimeException($ex->getMessage(), $ex->getCode(), $ex);
        } catch (\Exception $ex) {
            $this->reportFailure();
            $this->getEventManager()->trigger('request.fail', $this, $ex);
            throw new RuntimeException($ex->getMessage(), 500, $ex);
        }

        $this->getEventManager()->trigger('request.post', $this);

        $content = $response->getContent();

        return $content;
    }
1121655
public function create($limit = 500, $source = null, $destination = './')
    {
        if (!$destination || trim($destination) == '') {
            $destination = './';
        }

        $this->_rglobRead($source, $input);
        $maxinput = count($input);
        $splitinto = (($maxinput / $limit) > round($maxinput / $limit, 0)) ? round($maxinput / $limit, 0) + 1 : round($maxinput / $limit, 0);

        for ($i = 0; $i < $splitinto; ++$i) {
            $this->_zip(array_slice($input, ($i * $limit), $limit, true), $i, $destination);
        }

        unset($input);

        return;
    }
582007
def rate_limit(limit: int, key=None):
    

    def decorator(func):
        setattr(func, 'throttling_rate_limit', limit)
        if key:
            setattr(func, 'throttling_key', key)
        return func

    return decorator
1096489
public function setHeaders($headers, $override = true)
    {
        if ($override == false) {
            $this->headers = array_merge($headers, $this->headers);
        } else {
            $this->headers = $headers;
        }

        return $this;
    }
250938
protected function firstHeader($key, array $headers, $default = null)
    {
        if ( ! isset($headers[$key])) {
            return $default;
        }

        return is_array($headers[$key])
            ? reset($headers[$key])
            : $headers[$key];
    }
1079083
public static function exception(Exception $e, $httpCode = 500, $headers = NULL)
	{
		if ($e instanceof HTTP_Exception_Redirect) throw $e;
		if ($e instanceof HTTP_Exception) $httpCode = $e->getCode() ;

		self::json(Helpers_Exception::toArray($e), $httpCode, $headers);
	}
237571
public function setHeaders(array $headers, $overwrite_existing = false)
    {
        if ($overwrite_existing) {
            $this->curl_opts[CURLOPT_HTTPHEADER] = $headers;
        } else {
            $this->curl_opts[CURLOPT_HTTPHEADER] = array_merge(
                $this->curl_opts[CURLOPT_HTTPHEADER],
                $headers
            );
        }
    }
1100846
public function sendHeaders()
    {
        if (empty($this->headers)) {
            return;
        }

        $this->checkIfHeadersAlreadySent();

        foreach ($this->headers as $header) {
            switch ($header) {
                case '403':
                    header('HTTP/1.0 403 Forbidden');
                    break;

                case '404':
                    header('HTTP/1.0 404 Not Found');
                    break;

                case '500':
                    header('HTTP/1.0 500 Internal Server Error');
                    break;

                default:
                    throw new \Exception("Trying to sen unkown header type: '$header'.");
            }
        }

        return $this;
    }