AbstractHttp2ConnectionHandlerBuilder validateHeaders cannot be set with encoder/decoder

Motivation:
If validateHeaders is set in combination with the encoder/decoder it will be silently ignored. We should enforce the constraint that validateHeaders and encoder/decoder are mutually exclusive.

Modifications:
- Make sure either validateHeaders can be set or encoder/decoder.

Result:
AbstractHttp2ConnectionHandlerBuilder does not allow conflicting options to be set.
This commit is contained in:
Scott Mitchell 2016-01-22 14:19:40 -08:00
parent c3e5604f59
commit 78b508a7eb

View File

@ -73,7 +73,6 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
private static final SensitivityDetector DEFAULT_HEADER_SENSITIVITY_DETECTOR = Http2HeadersEncoder.NEVER_SENSITIVE;
// The properties that can always be set.
private boolean validateHeaders = true;
private Http2Settings initialSettings = new Http2Settings();
private Http2FrameListener frameListener;
private long gracefulShutdownTimeoutMillis = DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT_MILLIS;
@ -92,27 +91,11 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
// The properties that are:
// * mutually exclusive against codec() and
// * OK to use with server() and connection()
private Boolean validateHeaders;
private Http2FrameLogger frameLogger;
private SensitivityDetector headerSensitivityDetector;
private Boolean encoderEnforceMaxConcurrentStreams;
/**
* Returns if HTTP headers should be validated according to
* <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.6">RFC 7540, 8.1.2.6</a>.
*/
protected boolean isValidateHeaders() {
return validateHeaders;
}
/**
* Sets if HTTP headers should be validated according to
* <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.6">RFC 7540, 8.1.2.6</a>.
*/
protected B validateHeaders(boolean validateHeaders) {
this.validateHeaders = validateHeaders;
return self();
}
/**
* Sets the {@link Http2Settings} to use for the initial connection settings exchange.
*/
@ -229,6 +212,7 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
enforceConstraint("codec", "server", isServer);
enforceConstraint("codec", "connection", connection);
enforceConstraint("codec", "frameLogger", frameLogger);
enforceConstraint("codec", "validateHeaders", validateHeaders);
enforceConstraint("codec", "headerSensitivityDetector", headerSensitivityDetector);
enforceConstraint("codec", "encoderEnforceMaxConcurrentStreams", encoderEnforceMaxConcurrentStreams);
@ -245,6 +229,24 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
return self();
}
/**
* Returns if HTTP headers should be validated according to
* <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.6">RFC 7540, 8.1.2.6</a>.
*/
protected boolean isValidateHeaders() {
return validateHeaders != null ? validateHeaders : true;
}
/**
* Sets if HTTP headers should be validated according to
* <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.6">RFC 7540, 8.1.2.6</a>.
*/
protected B validateHeaders(boolean validateHeaders) {
enforceNonCodecConstraints("validateHeaders");
this.validateHeaders = validateHeaders;
return self();
}
/**
* Returns the logger that is used for the encoder and decoder.
*
@ -315,7 +317,7 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
}
private T buildFromConnection(Http2Connection connection) {
Http2FrameReader reader = new DefaultHttp2FrameReader(validateHeaders);
Http2FrameReader reader = new DefaultHttp2FrameReader(isValidateHeaders());
Http2FrameWriter writer = new DefaultHttp2FrameWriter(headerSensitivityDetector());
if (frameLogger != null) {