forked from kenzuya/unshackle
feat(tunnel): free finished tunnels at once and wait out 429s on --remote
A tunnel closed with code 1000 is freed without the 60s grace, a shared: true API key counts tunnels per X-Client-Id, and --remote waits out Retry-After and a full tunnel cap with a countdown; responses carry X-RateLimit-* headers.
This commit is contained in:
@@ -183,6 +183,18 @@ class ServerStats:
|
||||
entry.window_used += 1
|
||||
return None
|
||||
|
||||
def rate_limit_headers(self, key: str) -> Dict[str, str]:
|
||||
"""The ``X-RateLimit-*`` headers for ``key``'s current window; none for an API key with no limit."""
|
||||
limit = key_rate_limit(key)
|
||||
if limit is None:
|
||||
return {}
|
||||
entry = self.key_stats(key)
|
||||
return {
|
||||
"X-RateLimit-Limit": str(limit),
|
||||
"X-RateLimit-Remaining": str(max(0, limit - entry.window_used)),
|
||||
"X-RateLimit-Reset": str(max(0, int(entry.window_start + RATE_LIMIT_WINDOW - time.time()))),
|
||||
}
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"version": __version__,
|
||||
|
||||
Reference in New Issue
Block a user