Path: blob/master/support/startup/PhabricatorClientRateLimit.php
12240 views
<?php12final class PhabricatorClientRateLimit3extends PhabricatorClientLimit {45protected function getBucketDuration() {6return 60;7}89protected function getBucketCount() {10return 5;11}1213protected function shouldRejectConnection($score) {14$limit = $this->getLimit();1516// Reject connections if the average score across all buckets exceeds the17// limit.18$average_score = $score / $this->getBucketCount();1920return ($average_score > $limit);21}2223protected function getConnectScore() {24return 0;25}2627protected function getPenaltyScore() {28return 1;29}3031protected function getDisconnectScore(array $request_state) {32$score = 1;3334// If the user was logged in, let them make more requests.35if (isset($request_state['viewer'])) {36$viewer = $request_state['viewer'];37if ($viewer->isOmnipotent()) {38// If the viewer was omnipotent, this was an intracluster request or39// some other kind of special request, so don't give it any points40// toward rate limiting.41$score = 0;42} else if ($viewer->isLoggedIn()) {43// If the viewer was logged in, give them fewer points than if they44// were logged out, since this traffic is much more likely to be45// legitimate.46$score = 0.25;47}48}4950return $score;51}5253protected function getRateLimitReason($score) {54$client_key = $this->getClientKey();5556// NOTE: This happens before we load libraries, so we can not use pht()57// here.5859return60"TOO MANY REQUESTS\n".61"You (\"{$client_key}\") are issuing too many requests ".62"too quickly.\n";63}6465}666768