This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new 73b1d69768 Add attribute for error status code 73b1d69768 is described below commit 73b1d69768ebc24e2d6d2d2f15b7c2e2670bc40d 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 | 6 ++++++ webapps/docs/config/valve.xml | 7 +++++++ 3 files changed, 31 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 adf2b62598..7c29321e12 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -150,6 +150,12 @@ rewrite valve to allow skipping over the next valve in the Catalina pipeline. (remm) </update> + <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> <subsection name="Coyote"> diff --git a/webapps/docs/config/valve.xml b/webapps/docs/config/valve.xml index 18fa9cddd7..7f859cc2cd 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