From 481cedaa94ed45e41cd089e5e04bef2ee3c4d58c Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 13 Mar 2019 16:43:11 +1100 Subject: [PATCH] Issue #3012 Compliance modes. Fixed up httpCompliance configuration. Signed-off-by: Greg Wilkins --- .../eclipse/jetty/http/HttpCompliance.java | 35 +++++++++++++------ jetty-server/src/main/config/etc/jetty.xml | 1 + jetty-server/src/main/config/modules/http.mod | 3 -- .../src/main/config/modules/server.mod | 6 ++-- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCompliance.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCompliance.java index 37a9a19271e..0671b60162d 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCompliance.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpCompliance.java @@ -23,6 +23,7 @@ import java.util.EnumSet; import java.util.List; import java.util.Objects; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -31,7 +32,6 @@ import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableSet; import static java.util.EnumSet.allOf; import static java.util.EnumSet.complementOf; -import static java.util.EnumSet.copyOf; import static java.util.EnumSet.noneOf; import static java.util.EnumSet.of; @@ -99,6 +99,7 @@ public final class HttpCompliance implements ComplianceViolation.Mode private final static List KNOWN_MODES = Arrays.asList(RFC7230,RFC2616,LEGACY,RFC2616_LEGACY,RFC7230_LEGACY); + private final static AtomicInteger __custom = new AtomicInteger(); public static HttpCompliance valueOf(String name) { @@ -124,9 +125,9 @@ public final class HttpCompliance implements ComplianceViolation.Mode * with a '-' to exclude thm from the mode. *

*/ - static EnumSet violationBySpec(String spec) + public static HttpCompliance from(String spec) { - EnumSet sections; + Set sections; String[] elements = spec.split("\\s*,\\s*"); switch(elements[0]) { @@ -164,10 +165,9 @@ public final class HttpCompliance implements ComplianceViolation.Mode sections.remove(section); else sections.add(section); - } - return sections; + return new HttpCompliance("CUSTOM" + __custom.getAndIncrement(), sections); } @@ -178,7 +178,7 @@ public final class HttpCompliance implements ComplianceViolation.Mode { Objects.nonNull(violations); _name = name; - _violations = unmodifiableSet(copyOf(violations)); + _violations = unmodifiableSet(violations.isEmpty()?noneOf(Violation.class):copyOf(violations)); } @Override @@ -217,8 +217,8 @@ public final class HttpCompliance implements ComplianceViolation.Mode */ public HttpCompliance with(String name, Violation... violations) { - EnumSet union = _violations.isEmpty()?EnumSet.noneOf(Violation.class):copyOf(_violations); - union.addAll(copyOf(asList(violations))); + Set union = _violations.isEmpty()?EnumSet.noneOf(Violation.class):copyOf(_violations); + union.addAll(copyOf(violations)); return new HttpCompliance(name, union); } @@ -230,8 +230,8 @@ public final class HttpCompliance implements ComplianceViolation.Mode */ public HttpCompliance without(String name, Violation... violations) { - EnumSet remainder = _violations.isEmpty()?EnumSet.noneOf(Violation.class):copyOf(_violations); - remainder.removeAll(copyOf(asList(violations))); + Set remainder = _violations.isEmpty()?EnumSet.noneOf(Violation.class):copyOf(_violations); + remainder.removeAll(copyOf(violations)); return new HttpCompliance(name, remainder); } @@ -240,4 +240,19 @@ public final class HttpCompliance implements ComplianceViolation.Mode { return String.format("%s%s",_name,_violations); } + + + private static Set copyOf(Violation[] violations) + { + if (violations==null || violations.length==0) + return EnumSet.noneOf(Violation.class); + return EnumSet.copyOf(asList(violations)); + } + + private static Set copyOf(Set violations) + { + if (violations==null || violations.isEmpty()) + return EnumSet.noneOf(Violation.class); + return EnumSet.copyOf(violations); + } } diff --git a/jetty-server/src/main/config/etc/jetty.xml b/jetty-server/src/main/config/etc/jetty.xml index 365bdbdf7cf..f949648f440 100644 --- a/jetty-server/src/main/config/etc/jetty.xml +++ b/jetty-server/src/main/config/etc/jetty.xml @@ -67,6 +67,7 @@ + diff --git a/jetty-server/src/main/config/modules/http.mod b/jetty-server/src/main/config/modules/http.mod index 430d8519e2e..e1f89b00dbe 100644 --- a/jetty-server/src/main/config/modules/http.mod +++ b/jetty-server/src/main/config/modules/http.mod @@ -41,6 +41,3 @@ etc/jetty-http.xml ## Connect Timeout in milliseconds # jetty.http.connectTimeout=15000 - -## HTTP Compliance: RFC7230, RFC7230_LEGACY, RFC2616, RFC2616_LEGACY, LEGACY or CUSTOMn -# jetty.http.compliance=RFC7230_LEGACY diff --git a/jetty-server/src/main/config/modules/server.mod b/jetty-server/src/main/config/modules/server.mod index d07f9d63c0e..be9bff04e0d 100644 --- a/jetty-server/src/main/config/modules/server.mod +++ b/jetty-server/src/main/config/modules/server.mod @@ -59,15 +59,15 @@ etc/jetty.xml ## Maximum number of error dispatches to prevent looping # jetty.httpConfig.maxErrorDispatches=10 +## HTTP Compliance: RFC7230, RFC7230_LEGACY, RFC2616, RFC2616_LEGACY, LEGACY +# jetty.httpConfig.compliance=RFC7230 + ## Cookie compliance mode for parsing request Cookie headers: RFC2965, RFC6265 # jetty.httpConfig.requestCookieCompliance=RFC6265 ## Cookie compliance mode for generating response Set-Cookie: RFC2965, RFC6265 # jetty.httpConfig.responseCookieCompliance=RFC6265 -## multipart/form-data compliance mode of: LEGACY(slow), RFC7578(fast) -# jetty.httpConfig.multiPartFormDataCompliance=LEGACY - ### Server configuration ## Whether ctrl+c on the console gracefully stops the Jetty server # jetty.server.stopAtShutdown=true