Issue #3012 Compliance modes.

added valueOf methods for XML calls.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-03-13 15:43:38 +11:00
parent c7f66521cb
commit d8695f0712
3 changed files with 29 additions and 12 deletions

View File

@ -18,7 +18,9 @@
package org.eclipse.jetty.http; package org.eclipse.jetty.http;
import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -33,7 +35,6 @@ import static java.util.EnumSet.noneOf;
*/ */
public class CookieCompliance implements ComplianceViolation.Mode public class CookieCompliance implements ComplianceViolation.Mode
{ {
enum Violation implements ComplianceViolation enum Violation implements ComplianceViolation
{ {
COMMA_NOT_VALID_OCTET("https://tools.ietf.org/html/rfc6265#section-4.1.1", "Comma not valid as cookie-octet or separator"), COMMA_NOT_VALID_OCTET("https://tools.ietf.org/html/rfc6265#section-4.1.1", "Comma not valid as cookie-octet or separator"),
@ -70,6 +71,16 @@ public class CookieCompliance implements ComplianceViolation.Mode
public static final CookieCompliance RFC6265 = new CookieCompliance("RFC6265", noneOf(Violation.class)); public static final CookieCompliance RFC6265 = new CookieCompliance("RFC6265", noneOf(Violation.class));
public static final CookieCompliance RFC2965 = new CookieCompliance("RFC2965", allOf(Violation.class)); public static final CookieCompliance RFC2965 = new CookieCompliance("RFC2965", allOf(Violation.class));
private final static List<CookieCompliance> KNOWN_MODES = Arrays.asList(RFC6265,RFC2965);
public static CookieCompliance valueOf(String name)
{
for (CookieCompliance compliance : KNOWN_MODES)
if (compliance.getName().equals(name))
return compliance;
return null;
}
private final String _name; private final String _name;
private final Set<Violation> _violations; private final Set<Violation> _violations;

View File

@ -22,7 +22,6 @@ import java.util.Arrays;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
@ -85,6 +84,9 @@ public final class HttpCompliance implements ComplianceViolation.Mode
} }
} }
private static final Logger LOG = Log.getLogger(HttpParser.class);
public static final String VIOLATIONS_ATTR = "org.eclipse.jetty.http.compliance.violations";
public final static HttpCompliance RFC7230 = new HttpCompliance("RFC7230", noneOf(Violation.class)); public final static HttpCompliance RFC7230 = new HttpCompliance("RFC7230", noneOf(Violation.class));
public final static HttpCompliance RFC2616 = new HttpCompliance("RFC2616", of(Violation.HTTP_0_9, Violation.MULTILINE_FIELD_VALUE)); public final static HttpCompliance RFC2616 = new HttpCompliance("RFC2616", of(Violation.HTTP_0_9, Violation.MULTILINE_FIELD_VALUE));
public final static HttpCompliance LEGACY = new HttpCompliance("LEGACY", complementOf(of(Violation.CASE_INSENSITIVE_METHOD))); public final static HttpCompliance LEGACY = new HttpCompliance("LEGACY", complementOf(of(Violation.CASE_INSENSITIVE_METHOD)));
@ -95,11 +97,16 @@ public final class HttpCompliance implements ComplianceViolation.Mode
Violation.MULTIPLE_CONTENT_LENGTHS); Violation.MULTIPLE_CONTENT_LENGTHS);
public final static HttpCompliance RFC7230_LEGACY = RFC7230.with("RFC7230_LEGACY", Violation.CASE_INSENSITIVE_METHOD); public final static HttpCompliance RFC7230_LEGACY = RFC7230.with("RFC7230_LEGACY", Violation.CASE_INSENSITIVE_METHOD);
public final static List<HttpCompliance> KNOWN_MODES = Arrays.asList(RFC7230,RFC2616,LEGACY,RFC2616_LEGACY,RFC7230_LEGACY);
public static final String VIOLATIONS_ATTR = "org.eclipse.jetty.http.compliance.violations"; private final static List<HttpCompliance> KNOWN_MODES = Arrays.asList(RFC7230,RFC2616,LEGACY,RFC2616_LEGACY,RFC7230_LEGACY);
private static final Logger LOG = Log.getLogger(HttpParser.class); public static HttpCompliance valueOf(String name)
{
for (HttpCompliance compliance : KNOWN_MODES)
if (compliance.getName().equals(name))
return compliance;
return null;
}
/** /**
* Create violation set from string * Create violation set from string
@ -133,12 +140,11 @@ public final class HttpCompliance implements ComplianceViolation.Mode
default: default:
{ {
Optional<HttpCompliance> mode = HttpCompliance mode = HttpCompliance.valueOf(elements[0]);
KNOWN_MODES.stream().filter(m -> m.getName().equals(elements[0])).findFirst(); if (mode==null)
if (mode.isPresent())
sections = copyOf(mode.get().getAllowed());
else
sections = noneOf(Violation.class); sections = noneOf(Violation.class);
else
sections = copyOf(mode.getAllowed());
} }
} }

View File

@ -532,9 +532,9 @@ public class HttpConfiguration implements Dumpable
return _httpCompliance; return _httpCompliance;
} }
public void setHttpCompliance(HttpCompliance _httpCompliance) public void setHttpCompliance(HttpCompliance httpCompliance)
{ {
this._httpCompliance = _httpCompliance; _httpCompliance = httpCompliance;
} }
/** /**