Top Description Inners Fields Constructors Methods
org.eclipse.jetty.http

public final Class HttpCompliance

extends Object
implements Mode
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.http.ComplianceViolation.Mode
Imports
java.util.Arrays, .EnumSet, .List, .Objects, .Set, java.util.concurrent.atomic.AtomicInteger, org.eclipse.jetty.util.StringUtil, org.slf4j.Logger, .LoggerFactory

HTTP compliance modes for Jetty HTTP parsing and handling. A Compliance mode consists of a set of Violations which are applied when the mode is enabled.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
private static final AtomicInteger
private final String
private final Set<HttpCompliance.Violation>
private static final List<HttpCompliance>
public static final HttpCompliance
LEGACY

A legacy HttpCompliance mode that allows all violations except case-insensitive methods.

private static final Logger
public static final HttpCompliance
RFC2616

The HttpCompliance mode that supports RFC 7230 with only the violations that differ from RFC7230.

public static final HttpCompliance
RFC2616_LEGACY

A legacy HttpCompliance mode that supports RFC2616, but that also allows: case-insensitive methods; colons after field names; Transfer-Encoding with Content-Length fields; and multiple Content-Length values.

public static final HttpCompliance
RFC7230

The HttpCompliance mode that supports RFC 7230 with no known violations.

public static final HttpCompliance
RFC7230_LEGACY

A legacy HttpCompliance mode that supports RFC7230, but with case-insensitive methods allowed.

public static final String
VIOLATIONS_ATTR

Deprecated for removal since 12.0.6. use ComplianceViolation.CapturingListener#VIOLATIONS_ATTR_KEY instead.
The request attribute which may be set to record any allowed HTTP violations.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
private static void
public static void
private static Set<HttpCompliance.Violation>
private static Set<HttpCompliance.Violation>
public static HttpCompliance

Returns:

the HttpCompliance instance derived from the string description
from
(String
A string describing the compliance
spec
)

Create compliance mode from a String description.

public Set<HttpCompliance.Violation>
public Set<HttpCompliance.Violation>
public String
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public static HttpCompliance

Returns:

The mode matching the name.
valueOf
(String
The name of a known HttpCompliance mode.
name
)

Get a known compliance mode by name.

public HttpCompliance

Returns:

A new HttpCompliance mode.
with
(String
The name of the new mode
name
,
HttpCompliance.Violation...
The violations to include
violations
)

Create a new HttpCompliance mode that includes the passed Violations.

public HttpCompliance

Returns:

A new HttpCompliance mode.
without
(String
The name of the new mode
name
,
HttpCompliance.Violation...
The violations to exclude
violations
)

Create a new HttpCompliance mode that excludes the passed Violations.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

__customback to summary
private static final AtomicInteger __custom
_nameback to summary
private final String _name
_violationsback to summary
private final Set<HttpCompliance.Violation> _violations
KNOWN_MODESback to summary
private static final List<HttpCompliance> KNOWN_MODES
LEGACYback to summary
public static final HttpCompliance LEGACY

A legacy HttpCompliance mode that allows all violations except case-insensitive methods.

LOGback to summary
private static final Logger LOG
RFC2616back to summary
public static final HttpCompliance RFC2616

The HttpCompliance mode that supports RFC 7230 with only the violations that differ from RFC7230.

RFC2616_LEGACYback to summary
public static final HttpCompliance RFC2616_LEGACY

A legacy HttpCompliance mode that supports RFC2616, but that also allows: case-insensitive methods; colons after field names; Transfer-Encoding with Content-Length fields; and multiple Content-Length values.

RFC7230back to summary
public static final HttpCompliance RFC7230

The HttpCompliance mode that supports RFC 7230 with no known violations.

RFC7230_LEGACYback to summary
public static final HttpCompliance RFC7230_LEGACY

A legacy HttpCompliance mode that supports RFC7230, but with case-insensitive methods allowed.

VIOLATIONS_ATTRback to summary
public static final String VIOLATIONS_ATTR

Deprecated

for removal since 12.0.6.

use ComplianceViolation.CapturingListener#VIOLATIONS_ATTR_KEY instead.
(Note: new ATTR captures all Compliance violations, not just HTTP.
Make sure you have HttpConnectionFactory.setRecordHttpComplianceViolations(true).
Also make sure that a ComplianceViolation.CapturingListener has been added as a bean to either the Connector or Server for the Attribute to be created.)

The request attribute which may be set to record any allowed HTTP violations.

Annotations
@Deprecated
since:12.0.6
forRemoval:true

Constructor Detail

HttpComplianceback to summary
private HttpCompliance(String name, Set<HttpCompliance.Violation> violations)

Method Detail

allowsback to summary
public boolean allows(ComplianceViolation violation)

Implements org.eclipse.jetty.http.ComplianceViolation.Mode.allows.

Parameters
violation:ComplianceViolation

Doc from org.eclipse.jetty.http.ComplianceViolation.Mode.allows.

The ComplianceViolation to test

Returns:boolean

Doc from org.eclipse.jetty.http.ComplianceViolation.Mode.allows.

true iff the violation is allowed by this mode.

Annotations
@Override
assertAllowedback to summary
private static void assertAllowed(HttpCompliance.Violation violation, HttpCompliance mode, ComplianceViolation.Listener listener)
checkHttpComplianceback to summary
public static void checkHttpCompliance(MetaData.Request request, HttpCompliance mode, ComplianceViolation.Listener listener)
copyOfback to summary
private static Set<HttpCompliance.Violation> copyOf(HttpCompliance.Violation[] violations)
copyOfback to summary
private static Set<HttpCompliance.Violation> copyOf(Set<HttpCompliance.Violation> violations)
fromback to summary
public static HttpCompliance from(String spec)

Create compliance mode from a String description.

Format:

0
No Violations
*
All Violations
RFC2616
The set of Violations application to RFC2616, but not RFC7230
RFC7230
The set of Violations application to RFC7230
name
Any of the known modes defined in HttpCompliance#KNOWN_MODES

The remainder of the list can contain then names of Violations to include them in the mode, or prefixed with a '-' to exclude them from the mode.

Parameters
spec:String

A string describing the compliance

Returns:HttpCompliance

the HttpCompliance instance derived from the string description

getAllowedback to summary
public Set<HttpCompliance.Violation> getAllowed()

Implements org.eclipse.jetty.http.ComplianceViolation.Mode.getAllowed.

Returns:Set<HttpCompliance.Violation>

Doc from org.eclipse.jetty.http.ComplianceViolation.Mode.getAllowed.

The immutable set of violations allowed by this mode.

Annotations
@Override
getKnownback to summary
public Set<HttpCompliance.Violation> getKnown()

Implements org.eclipse.jetty.http.ComplianceViolation.Mode.getKnown.

Returns:Set<HttpCompliance.Violation>

Doc from org.eclipse.jetty.http.ComplianceViolation.Mode.getKnown.

The immutable set of all known violations for this mode.

Annotations
@Override
getNameback to summary
public String getName()

Implements org.eclipse.jetty.http.ComplianceViolation.Mode.getName.

Returns:String

Doc from org.eclipse.jetty.http.ComplianceViolation.Mode.getName.

The name of the compliance violation mode.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
valueOfback to summary
public static HttpCompliance valueOf(String name)

Get a known compliance mode by name.

Parameters
name:String

The name of a known HttpCompliance mode.

Returns:HttpCompliance

The mode matching the name.

withback to summary
public HttpCompliance with(String name, HttpCompliance.Violation... violations)

Create a new HttpCompliance mode that includes the passed Violations.

Parameters
name:String

The name of the new mode

violations:HttpCompliance.Violation[]

The violations to include

Returns:HttpCompliance

A new HttpCompliance mode.

withoutback to summary
public HttpCompliance without(String name, HttpCompliance.Violation... violations)

Create a new HttpCompliance mode that excludes the passed Violations.

Parameters
name:String

The name of the new mode

violations:HttpCompliance.Violation[]

The violations to exclude

Returns:HttpCompliance

A new HttpCompliance mode.

org.eclipse.jetty.http back to summary

public final Enum HttpCompliance.Violation

extends Enum<HttpCompliance.Violation>
implements ComplianceViolation
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.http.ComplianceViolation

Field Summary

Modifier and TypeField and Description
public static final HttpCompliance.Violation
CASE_INSENSITIVE_METHOD

The HTTP RFC(s) require that method names are case-sensitive, so that "Get" and "GET" are considered different methods.

public static final HttpCompliance.Violation
CASE_SENSITIVE_FIELD_NAME

The HTTP RFC(s) require that field names are case-insensitive, so for example the fields "Content-Type: text/xml" and "content-type: text/xml" are considered equivalent.

private final String
public static final HttpCompliance.Violation
DUPLICATE_HOST_HEADERS

Since RFC 7230: Section 5.4, the HTTP protocol says that a Server must reject a request duplicate host headers.

public static final HttpCompliance.Violation
HTTP_0_9

Since RFC 7230, the expectation that HTTP/0.9 is supported has been removed from the specification.

public static final HttpCompliance.Violation
MISMATCHED_AUTHORITY

Since RFC 7230: Section 5.4, the HTTP protocol must reject a request if the target URI has an authority that is different than a provided Host header.

public static final HttpCompliance.Violation
MULTILINE_FIELD_VALUE

Since RFC 7230, the HTTP protocol no longer supports line folding, which allows a field value to be provided over several lines.

public static final HttpCompliance.Violation
MULTIPLE_CONTENT_LENGTHS

Since RFC 7230, the HTTP protocol has required that a request is invalid if it contains multiple Content-Length fields or values.

public static final HttpCompliance.Violation
NO_COLON_AFTER_FIELD_NAME

Prior to RFC 7230, the HTTP protocol allowed a header line of a single token with neither a colon nor value following, to be interpreted as a field name with no value.

public static final HttpCompliance.Violation
TRANSFER_ENCODING_WITH_CONTENT_LENGTH

Since RFC 7230, the HTTP protocol has required that a request is invalid if it contains both a Transfer-Encoding field and Content-Length field.

public static final HttpCompliance.Violation
UNSAFE_HOST_HEADER

Since RFC 7230, the HTTP protocol should reject a request if the Host headers contains an invalid / unsafe authority.

private final String
public static final HttpCompliance.Violation
WHITESPACE_AFTER_FIELD_NAME

Since RFC 7230, the HTTP protocol has required that a request header field has no white space after the field name and before the ':'.

Constructor Summary

AccessConstructor and Description
private
Violation(String url, String description)

Method Summary

Modifier and TypeMethod and Description
public String
public String
public String
public static HttpCompliance.Violation
public static HttpCompliance.Violation[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CASE_INSENSITIVE_METHODback to summary
public static final HttpCompliance.Violation CASE_INSENSITIVE_METHOD

The HTTP RFC(s) require that method names are case-sensitive, so that "Get" and "GET" are considered different methods. Jetty releases prior to 9.4 used a case-insensitive cache to match method names, thus this requirement was violated. Deployments which wish to retain this legacy violation can include this violation in the HttpCompliance mode.

CASE_SENSITIVE_FIELD_NAMEback to summary
public static final HttpCompliance.Violation CASE_SENSITIVE_FIELD_NAME

The HTTP RFC(s) require that field names are case-insensitive, so for example the fields "Content-Type: text/xml" and "content-type: text/xml" are considered equivalent. Jetty has been optimized to take advantage of this by looking up field names in a case-insensitive cache and will by default provide the standard capitalisation of a field name rather than create a new string with the actual capitalisation received. However, some applications have been written to expect a specific capitalisation of field, so deployments of such applications must include this violation in their HttpCompliance mode to prevent Jetty altering the case of the fields received. Jetty itself will still match and handle fields names insensitively and this violation only affects how the names are reported to the application. There is a small performance and garbage impact of using this mode.

descriptionback to summary
private final String description
DUPLICATE_HOST_HEADERSback to summary
public static final HttpCompliance.Violation DUPLICATE_HOST_HEADERS

Since RFC 7230: Section 5.4, the HTTP protocol says that a Server must reject a request duplicate host headers. A deployment may include this violation to allow duplicate host headers on a received request.

HTTP_0_9back to summary
public static final HttpCompliance.Violation HTTP_0_9

Since RFC 7230, the expectation that HTTP/0.9 is supported has been removed from the specification. If a deployment wished to accept HTTP/0.9 requests, then it can include this violation in it's HttpCompliance mode.

MISMATCHED_AUTHORITYback to summary
public static final HttpCompliance.Violation MISMATCHED_AUTHORITY

Since RFC 7230: Section 5.4, the HTTP protocol must reject a request if the target URI has an authority that is different than a provided Host header. A deployment may include this violation to allow different values on the target URI and the Host header on a received request.

MULTILINE_FIELD_VALUEback to summary
public static final HttpCompliance.Violation MULTILINE_FIELD_VALUE

Since RFC 7230, the HTTP protocol no longer supports line folding, which allows a field value to be provided over several lines. Deployments that wish to receive folder field values may include this violation in their HttpCompliance mode.

MULTIPLE_CONTENT_LENGTHSback to summary
public static final HttpCompliance.Violation MULTIPLE_CONTENT_LENGTHS

Since RFC 7230, the HTTP protocol has required that a request is invalid if it contains multiple Content-Length fields or values. The request may be treated as invalid even if the multiple values are the same. A deployment may include this violation to allow multiple Content-Length values to be received, but only if they are identical.

NO_COLON_AFTER_FIELD_NAMEback to summary
public static final HttpCompliance.Violation NO_COLON_AFTER_FIELD_NAME

Prior to RFC 7230, the HTTP protocol allowed a header line of a single token with neither a colon nor value following, to be interpreted as a field name with no value. A deployment may include this violation to allow such fields to be in a received request.

TRANSFER_ENCODING_WITH_CONTENT_LENGTHback to summary
public static final HttpCompliance.Violation TRANSFER_ENCODING_WITH_CONTENT_LENGTH

Since RFC 7230, the HTTP protocol has required that a request is invalid if it contains both a Transfer-Encoding field and Content-Length field. A deployment may include this violation to allow both fields to be in a received request.

UNSAFE_HOST_HEADERback to summary
public static final HttpCompliance.Violation UNSAFE_HOST_HEADER

Since RFC 7230, the HTTP protocol should reject a request if the Host headers contains an invalid / unsafe authority. A deployment may include this violation to allow unsafe host headesr on a received request.

urlback to summary
private final String url
WHITESPACE_AFTER_FIELD_NAMEback to summary
public static final HttpCompliance.Violation WHITESPACE_AFTER_FIELD_NAME

Since RFC 7230, the HTTP protocol has required that a request header field has no white space after the field name and before the ':'. A deployment may include this violation to allow such fields to be in a received request.

Constructor Detail

Violationback to summary
private Violation(String url, String description)

Method Detail

getDescriptionback to summary
public String getDescription()

Implements org.eclipse.jetty.http.ComplianceViolation.getDescription.

Returns:String

Doc from org.eclipse.jetty.http.ComplianceViolation.getDescription.

A short description of the violation.

Annotations
@Override
getNameback to summary
public String getName()

Implements org.eclipse.jetty.http.ComplianceViolation.getName.

Returns:String

Doc from org.eclipse.jetty.http.ComplianceViolation.getName.

The name of the violation.

Annotations
@Override
getURLback to summary
public String getURL()

Implements org.eclipse.jetty.http.ComplianceViolation.getURL.

Returns:String

Doc from org.eclipse.jetty.http.ComplianceViolation.getURL.

A URL to the specification that provides more information regarding the requirement that may be violated.

Annotations
@Override
valueOfback to summary
public static HttpCompliance.Violation valueOf(String name)
valuesback to summary
public static HttpCompliance.Violation[] values()