Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F679798
PhabricatorClientRateLimit.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
PhabricatorClientRateLimit.php
View Options
<?php
final
class
PhabricatorClientRateLimit
extends
PhabricatorClientLimit
{
protected
function
getBucketDuration
()
{
return
60
;
}
protected
function
getBucketCount
()
{
return
5
;
}
protected
function
shouldRejectConnection
(
$score
)
{
$limit
=
$this
->
getLimit
();
// Reject connections if the average score across all buckets exceeds the
// limit.
$average_score
=
$score
/
$this
->
getBucketCount
();
return
(
$average_score
>
$limit
);
}
protected
function
getConnectScore
()
{
return
0
;
}
protected
function
getPenaltyScore
()
{
return
1
;
}
protected
function
getDisconnectScore
(
array
$request_state
)
{
$score
=
1
;
// If the user was logged in, let them make more requests.
if
(
isset
(
$request_state
[
'viewer'
]))
{
$viewer
=
$request_state
[
'viewer'
];
if
(
$viewer
->
isOmnipotent
())
{
// If the viewer was omnipotent, this was an intracluster request or
// some other kind of special request, so don't give it any points
// toward rate limiting.
$score
=
0
;
}
else
if
(
$viewer
->
isLoggedIn
())
{
// If the viewer was logged in, give them fewer points than if they
// were logged out, since this traffic is much more likely to be
// legitimate.
$score
=
0.25
;
}
}
return
$score
;
}
protected
function
getRateLimitReason
(
$score
)
{
$client_key
=
$this
->
getClientKey
();
// NOTE: This happens before we load libraries, so we can not use pht()
// here.
return
"TOO MANY REQUESTS
\n
"
.
"You (
\"
{$client_key}
\"
) are issuing too many requests "
.
"too quickly.
\n
"
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 27, 8:47 AM (1 d, 12 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
166053
Default Alt Text
PhabricatorClientRateLimit.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment