Skip to content

Commit

Permalink
Merge branch 'main' into ratelimiting_exact_policy
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf authored Dec 16, 2024
2 parents d0748d6 + f73db90 commit 29c58d0
Show file tree
Hide file tree
Showing 28 changed files with 1,046 additions and 167 deletions.
5 changes: 5 additions & 0 deletions build.properties.default
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ java.net.preferIPv4Stack=false
# MacOS requires non-default settings to test FFM with OpenSSL. Eg:
#openssl.ffm.1=-Dorg.apache.tomcat.util.openssl.USE_SYSTEM_LOAD_LIBRARY=true
#openssl.ffm.2=-Dorg.apache.tomcat.util.openssl.LIBRARY_NAME=ssl
# Allows loading the crypto library using the JVM and the given name
# if using org.apache.tomcat.util.openssl.USE_SYSTEM_LOAD_LIBRARY
# (otherwise it is loaded later by ssl)
#openssl.ffm.3=-Dorg.apache.tomcat.util.openssl.CRYPTO_LIBRARY_NAME=crypto
openssl.ffm.1=-DNoop1
openssl.ffm.2=-DNoop2
openssl.ffm.3=-DNoop3


# ----- Release build settings -----
Expand Down
1 change: 1 addition & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,7 @@
<!-- These are managed as jvmargs rather than sysproperty because the default varies by OS -->
<jvmarg value="${openssl.ffm.1}" />
<jvmarg value="${openssl.ffm.2}" />
<jvmarg value="${openssl.ffm.3}" />

<classpath refid="tomcat.test.classpath" />

Expand Down
10 changes: 5 additions & 5 deletions conf/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
<!-- listings is enabled? [true] -->
<!-- -->
<!-- allowPartialPut Should the server treat an HTTP PUT request -->
<!-- with a Range header as a partial PUT? Note -->
<!-- that while RFC 7233 clarified that Range -->
<!-- headers only valid for GET requests, RFC 9110 -->
<!-- (which obsoletes RFC 7233) now allows partial -->
<!-- puts. [true] -->
<!-- with a Content-Range header as a partial PUT? -->
<!-- Note that while RFC 7231 clarified that such a -->
<!-- PUT with a Content-Range header field is a bad -->
<!-- request, RFC 9110 (which obsoletes RFC 7231) -->
<!-- now allows partial PUT. [true] -->
<!-- -->
<!-- directoryRedirectStatusCode -->
<!-- Status code to use for directory redirects. -->
Expand Down
392 changes: 269 additions & 123 deletions java/org/apache/catalina/servlets/DefaultServlet.java

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion java/org/apache/catalina/startup/ExpandWar.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ public static String expand(Host host, URL war, String pathname) throws IOExcept
File warTracker = new File(host.getAppBaseFile(), pathname + Constants.WarTracker);
long warLastModified = -1;

try (InputStream is = jfuc.getInputStream()) {
try (@SuppressWarnings("unused")
InputStream is = jfuc.getInputStream()) {
// Get the last modified time for the WAR
warLastModified = jfuc.getLastModified();
}
Expand Down
2 changes: 1 addition & 1 deletion java/org/apache/catalina/startup/HostConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ protected void check() {
*/
public void check(String name) {
synchronized (host) {
if (!((Lifecycle) host).getState().isAvailable()) {
if (!host.getState().isAvailable()) {
return;
}
if (tryAddServiced(name)) {
Expand Down
4 changes: 4 additions & 0 deletions java/org/apache/coyote/http2/ConnectionSettingsBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ final void set(Setting setting, long value) throws T {
case NO_RFC7540_PRIORITIES:
validateNoRfc7540Priorities(value);
break;
case ENABLE_CONNECT_PROTOCOL:
case TLS_RENEG_PERMITTED:
// Not supported. Ignore it.
return;
case UNKNOWN:
// Unrecognised. Ignore it.
return;
Expand Down
8 changes: 8 additions & 0 deletions java/org/apache/coyote/http2/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ enum Setting {
INITIAL_WINDOW_SIZE(4),
MAX_FRAME_SIZE(5),
MAX_HEADER_LIST_SIZE(6),
ENABLE_CONNECT_PROTOCOL(8),
NO_RFC7540_PRIORITIES(9),
TLS_RENEG_PERMITTED(10),
UNKNOWN(Integer.MAX_VALUE);

private final int id;
Expand Down Expand Up @@ -61,9 +63,15 @@ static Setting valueOf(int i) {
case 6: {
return MAX_HEADER_LIST_SIZE;
}
case 8: {
return ENABLE_CONNECT_PROTOCOL;
}
case 9: {
return NO_RFC7540_PRIORITIES;
}
case 10: {
return TLS_RENEG_PERMITTED;
}
default: {
return UNKNOWN;
}
Expand Down
3 changes: 2 additions & 1 deletion java/org/apache/jasper/servlet/JspCServletContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ public URL getResource(String path) throws MalformedURLException {
try {
URI uri = new URI(myResourceBaseURL.toExternalForm() + path);
url = uri.toURL();
try (InputStream is = url.openStream()) {
try (@SuppressWarnings("unused")
InputStream is = url.openStream()) {
}
} catch (Throwable t) {
ExceptionUtils.handleThrowable(t);
Expand Down
3 changes: 1 addition & 2 deletions java/org/apache/juli/OneLineFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.lang.management.ThreadMXBean;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Formatter;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
Expand Down Expand Up @@ -253,7 +252,7 @@ private static class ThreadNameCache extends LinkedHashMap<Long, String> {
}

@Override
protected boolean removeEldestEntry(Entry<Long, String> eldest) {
protected boolean removeEldestEntry(Map.Entry<Long, String> eldest) {
return (size() > cacheSize);
}
}
Expand Down
4 changes: 4 additions & 0 deletions java/org/apache/tomcat/util/buf/ByteBufferUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public static ByteBuffer expand(ByteBuffer in, int newSize) {
return out;
}

/**
* Clean specified direct buffer. This will cause an unavoidable warning on Java 24 and newer.
* @param buf the buffer to clean
*/
public static void cleanDirectBuffer(ByteBuffer buf) {
if (invokeCleanerMethod != null) {
try {
Expand Down
11 changes: 7 additions & 4 deletions java/org/apache/tomcat/util/http/parser/EntityTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ public class EntityTag {
*/
public static Boolean compareEntityTag(StringReader input, boolean compareWeak, String resourceETag)
throws IOException {

Boolean result = Boolean.FALSE;

// The resourceETag may be weak so to do weak comparison remove /W
// before comparison
String comparisonETag;
if (compareWeak && resourceETag.startsWith("W/")) {
if (resourceETag == null) {
comparisonETag = null;
} else if (compareWeak && resourceETag.startsWith("W/")) {
comparisonETag = resourceETag.substring(2);
} else {
comparisonETag = resourceETag;
}

Boolean result = Boolean.FALSE;

while (true) {
boolean strong = false;
HttpParser.skipLws(input);
Expand All @@ -71,7 +74,7 @@ public static Boolean compareEntityTag(StringReader input, boolean compareWeak,
}

if (strong || compareWeak) {
if (comparisonETag.equals(value)) {
if (value.equals(comparisonETag)) {
result = Boolean.TRUE;
}
}
Expand Down
2 changes: 1 addition & 1 deletion java/org/apache/tomcat/util/net/Nio2Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -1702,7 +1702,7 @@ protected void doRun() {
} catch (Throwable t) {
log.error(sm.getString("endpoint.processing.fail"), t);
if (socketWrapper != null) {
((Nio2SocketWrapper) socketWrapper).close();
socketWrapper.close();
}
} finally {
if (launch) {
Expand Down
5 changes: 5 additions & 0 deletions java/org/apache/tomcat/util/openssl/openssl_h.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public class openssl_h {
/*
* On Mac OS SymbolLookup.libraryLookup() appears to ignore java.library.path which means the LibreSSL
* library will be found which will then fail. Therefore, skip that lookup on Mac OS.
* On other platforms this can also be used to give more flexibility when testing.
*/
public static final boolean USE_SYSTEM_LOAD_LIBRARY = Boolean.getBoolean("org.apache.tomcat.util.openssl.USE_SYSTEM_LOAD_LIBRARY");
public static final String CRYPTO_LIBRARY_NAME = System.getProperty("org.apache.tomcat.util.openssl.CRYPTO_LIBRARY_NAME");
public static final String LIBRARY_NAME = System.getProperty("org.apache.tomcat.util.openssl.LIBRARY_NAME",
(JrePlatform.IS_MAC_OS) ? "ssl.48" : "ssl");

Expand All @@ -61,6 +63,9 @@ public class openssl_h {
static final SymbolLookup SYMBOL_LOOKUP;
static {
if (USE_SYSTEM_LOAD_LIBRARY) {
if (CRYPTO_LIBRARY_NAME != null) {
System.loadLibrary(CRYPTO_LIBRARY_NAME);
}
System.loadLibrary(LIBRARY_NAME);
SYMBOL_LOOKUP = SymbolLookup.loaderLookup().or(Linker.nativeLinker().defaultLookup());
} else {
Expand Down
8 changes: 7 additions & 1 deletion modules/cxf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<name>Apache CXF for Apache Tomcat CDI</name>
<description>Apache CXF packaged for Apache Tomcat CDI</description>
<!-- This is the Apache CXF version -->
<version>4.0.4</version>
<version>4.1.0</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -146,6 +146,12 @@
<exclude>META-INF/services/jakarta.enterprise.inject.spi.Extension</exclude>
</excludes>
</filter>
<filter>
<artifact>org.apache.cxf:cxf-integration-cdi</artifact>
<excludes>
<exclude>META-INF/beans.xml</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public void run() {
@Override
public void run() {
// Expected to fail
try (Connection c = ds.getConnection()) {
try (@SuppressWarnings("unused")
Connection c = ds.getConnection()) {
} catch (Exception e) {
System.err.println("Step 2:"+e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public void testDefaultAbandon() throws Exception {
this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100);
this.datasource.getPoolProperties().setRemoveAbandoned(true);
this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1);
try (Connection con = datasource.getConnection()) {
try (@SuppressWarnings("unused")
Connection con = datasource.getConnection()) {
Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Thread.sleep(2000);
Assert.assertEquals("Number of connections active/busy should be 0",0,datasource.getPool().getActive());
Expand All @@ -51,7 +52,8 @@ public void testMaxedOutAbandon() throws Exception {
this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100);
this.datasource.getPoolProperties().setRemoveAbandoned(true);
this.datasource.getPoolProperties().setRemoveAbandonedTimeout(1);
try (Connection con = datasource.getConnection()) {
try (@SuppressWarnings("unused")
Connection con = datasource.getConnection()) {
Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Thread.sleep(2000);
Assert.assertEquals("Number of connections active/busy should be 1",1,datasource.getPool().getActive());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@

import org.junit.Test;

import org.apache.tomcat.jdbc.pool.DataSourceProxy;

public class Async0IdleTestBug50477 extends DefaultTestCase {

@Test
Expand All @@ -33,7 +31,7 @@ public void testAsync0Idle0Size() throws Exception {
this.datasource.getPoolProperties().setFairQueue(true);
this.datasource.getPoolProperties().setInitialSize(0);
try {
Future<Connection> cf = ((DataSourceProxy)datasource).getConnectionAsync();
Future<Connection> cf = datasource.getConnectionAsync();
cf.get(5, TimeUnit.SECONDS);
}finally {
tearDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class TestException extends DefaultTestCase {
public void testException() throws Exception {
datasource.getPoolProperties().setJdbcInterceptors(TestInterceptor.class.getName());
Connection con = datasource.getConnection();
try (Statement s = con.createStatement()){
try (@SuppressWarnings("unused")
Statement s = con.createStatement()){
} catch (Exception x) {
Assert.fail();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public static Collection<Object[]> parameters() {
// Valid
parameterSets.add(new Object[] {
"bytes=0-9", lastModified, Integer.valueOf(206), "10", "0-9/" + len });
// Nonsense date (return whole entity)
// Nonsense data (request rejected)
parameterSets.add(new Object[] {
"bytes=0-9", "a-b-c", Integer.valueOf(200), strLen, ""});
"bytes=0-9", "a-b-c", Integer.valueOf(400), null, ""});
// Different date (return whole entity)
parameterSets.add(new Object[] {
"bytes=0-9", FastHttpDateFormat.formatDate(1000), Integer.valueOf(200), strLen, ""});
Expand Down
Loading

0 comments on commit 29c58d0

Please sign in to comment.