This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new c939a4136a Add attribute for error status code c939a4136a is described below commit c939a4136ad2eb9c5928a084e9d1d8a26ee4f546 Author: remm <r...@apache.org> AuthorDate: Mon Mar 11 15:24:41 2024 +0100 Add attribute for error status code Part 1 of BZ 60997. Although subclasses can do it (that is the design of the valve), it seems very reasonable/simple to add it. --- java/org/apache/catalina/valves/SemaphoreValve.java | 19 ++++++++++++++++++- webapps/docs/changelog.xml | 10 ++++++++++ webapps/docs/config/valve.xml | 7 +++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/java/org/apache/catalina/valves/SemaphoreValve.java b/java/org/apache/catalina/valves/SemaphoreValve.java index 9a4edfd61e..6b4b5830ef 100644 --- a/java/org/apache/catalina/valves/SemaphoreValve.java +++ b/java/org/apache/catalina/valves/SemaphoreValve.java @@ -113,6 +113,21 @@ public class SemaphoreValve extends ValveBase { } + /** + * High concurrency status. This status code is returned as an + * error if concurrency is too high. + */ + protected int highConcurrencyStatus = -1; + + public int getHighConcurrencyStatus() { + return this.highConcurrencyStatus; + } + + public void setHighConcurrencyStatus(int highConcurrencyStatus) { + this.highConcurrencyStatus = highConcurrencyStatus; + } + + /** * Start this component and implement the requirements of * {@link org.apache.catalina.util.LifecycleBase#startInternal()}. @@ -213,7 +228,9 @@ public class SemaphoreValve extends ValveBase { * @throws ServletException Other error */ public void permitDenied(Request request, Response response) throws IOException, ServletException { - // NO-OP by default + if (highConcurrencyStatus > 0) { + response.sendError(highConcurrencyStatus); + } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 8b4bdbb4bf..1558eb7938 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -105,6 +105,16 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 11.0.0-M19 (markt)" rtext="in development"> + <subsection name="Catalina"> + <changelog> + <update> + Add <code>highConcurrencyStatus</code> attribute to the + <code>SemaphoreValve</code> to optionally allow the valve to return an + error status code to the client when a permit cannot be acquired from + the semaphore. (remm) + </update> + </changelog> + </subsection> </section> <section name="Tomcat 11.0.0-M18 (markt)" rtext="release in progress"> <subsection name="General"> diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml index 82f7b70e26..0be8bef9b4 100644 --- a/webapps/docs/config/valve.xml +++ b/webapps/docs/config/valve.xml @@ -2555,6 +2555,13 @@ <strong>false</strong>.</p> </attribute> + <attribute name="highConcurrencyStatus" required="false"> + <p>The error status code which will be returned to the client, if the + value is positive, when a permit cannot be acquired from the + sepmaphore. The default value is <strong>-1</strong>, which will mean + no error status will be sent back.</p> + </attribute> + <attribute name="interruptible" required="false"> <p>Flag to determine if a thread may be interrupted until a permit is available. The default value is <strong>false</strong>.</p> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org