ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/catalina/util/RateLimiter.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/catalina/util/RateLimiter.java
Status
scanned
Type
file
Name
RateLimiter.java
Extension
.java
Programming language
Java
Mime type
text/html
File type
HTML document, ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3662 (3.6 KB)
MD5
509ecf157ce9e51a75e61d767d494dcb
SHA1
6e61e534574a9e0c25b4bc4615a99cbf4fdd18ac
SHA256
0a0c3dbaaaec543a6e5bf7d53051ab5782308da524a1f993701305c6733ffdcb
SHA512

      
    
SHA1_git
55d706cc9664a5d89d011d8c6a3771e7387992ca
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
RateLimiter.java | 3.6 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.util; import jakarta.servlet.FilterConfig; public interface RateLimiter { /** * @return the actual duration of a time window in seconds */ int getDuration(); /** * Sets the configured duration value in seconds. * * @param duration The duration of the time window in seconds */ void setDuration(int duration); /** * @return the maximum number of requests allowed per time window */ int getRequests(); /** * Sets the configured number of requests allowed per time window. * * @param requests The number of requests per time window */ void setRequests(int requests); /** * Increments the number of requests by the given identifier in the current time window. * * @param identifier the identifier for which the number of associated requests should be incremented * * @return the new value after incrementing */ int increment(String identifier); /** * Cleanup no longer needed resources. */ void destroy(); /** * Pass the FilterConfig to configure the filter. * * @param filterConfig The FilterConfig used to configure the associated filter */ void setFilterConfig(FilterConfig filterConfig); /** * @return name of RateLimit policy */ String getPolicyName(); /** * Sets the policy name, otherwise an auto-generated name is used. * * @param name of rate limit policy */ void setPolicyName(String name); /** * @return full representation of current policy * * @see <a href="https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers">RateLimit header fields for * HTTP (draft)</a> */ default String getPolicy() { // enclose policy name with double quotes. e.g. "fixed-01";q=3000;w=60 return "\"" + getPolicyName() + "\";q=" + getRequests() + ";w=" + getDuration(); } /** * Provide the quota header for this rate limit for a given request count within the current time window. * * @param requestCount The request count within the current time window * * @return the quota header for the given value of request count * * @see <a href="https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers">RateLimit header fields for * HTTP (draft)</a> */ default String getQuota(int requestCount) { // Local copy to ensure consistency int maxRequests = getRequests(); int remaining = (requestCount < 0 || requestCount > maxRequests) ? 0 : (maxRequests - requestCount); return "\"" + getPolicyName() + "\";r=" + remaining; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
28.47
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9
https://datatracker.ietf.org/doc/draft-ietf-httpapi-ratelimit-headers 83 83