Remove non-standard header values from HttpHeaderValues

Motivation:

x-gzip and x-deflate are not standard header values, and thus should be
removed from HttpHeaderValues, which is meant to provide the standard
values only.

Modifications:

- Remove X_DEFLATE and X_GZIP from HttpHeaderValues
- Move X_DEFLATE and X_GZIP to HttpContentDecompressor and
  DelegatingDecompressorFrameListener
  - We have slight code duplication here, but it does less harm than
    having non-standard constant.

Result:

HttpHeaderValues contains only standard header values.
This commit is contained in:
Trustin Lee 2014-11-01 02:51:34 +09:00
parent f793f395d6
commit ceb06dc1b1
3 changed files with 24 additions and 12 deletions

View File

@ -16,6 +16,7 @@
package io.netty.handler.codec.http;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.AsciiString;
import io.netty.handler.codec.compression.ZlibCodecFactory;
import io.netty.handler.codec.compression.ZlibWrapper;
@ -26,6 +27,15 @@ import io.netty.handler.codec.compression.ZlibWrapper;
*/
public class HttpContentDecompressor extends HttpContentDecoder {
/**
* {@code "x-deflate"}
*/
private static final AsciiString X_DEFLATE = new AsciiString("x-deflate");
/**
* {@code "x-gzip"}
*/
private static final AsciiString X_GZIP = new AsciiString("x-gzip");
private final boolean strict;
/**
@ -48,11 +58,11 @@ public class HttpContentDecompressor extends HttpContentDecoder {
@Override
protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception {
if (HttpHeaderValues.GZIP.equalsIgnoreCase(contentEncoding) ||
HttpHeaderValues.X_GZIP.equalsIgnoreCase(contentEncoding)) {
X_GZIP.equalsIgnoreCase(contentEncoding)) {
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
if (HttpHeaderValues.DEFLATE.equalsIgnoreCase(contentEncoding) ||
HttpHeaderValues.X_DEFLATE.equalsIgnoreCase(contentEncoding)) {
X_DEFLATE.equalsIgnoreCase(contentEncoding)) {
final ZlibWrapper wrapper = strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(wrapper));

View File

@ -188,14 +188,6 @@ public final class HttpHeaderValues {
* {@code "websocket"}
*/
public static final AsciiString WEBSOCKET = new AsciiString("websocket");
/**
* {@code "x-deflate"}
*/
public static final AsciiString X_DEFLATE = new AsciiString("x-deflate");
/**
* {@code "x-gzip"}
*/
public static final AsciiString X_GZIP = new AsciiString("x-gzip");
private HttpHeaderValues() { }
}

View File

@ -30,6 +30,16 @@ import io.netty.handler.codec.http.HttpHeaderValues;
* stream.
*/
public class DelegatingDecompressorFrameListener extends Http2FrameListenerDecorator {
/**
* {@code "x-deflate"}
*/
private static final AsciiString X_DEFLATE = new AsciiString("x-deflate");
/**
* {@code "x-gzip"}
*/
private static final AsciiString X_GZIP = new AsciiString("x-gzip");
private static final Http2ConnectionAdapter CLEAN_UP_LISTENER = new Http2ConnectionAdapter() {
@Override
public void streamRemoved(Http2Stream stream) {
@ -121,11 +131,11 @@ public class DelegatingDecompressorFrameListener extends Http2FrameListenerDecor
*/
protected EmbeddedChannel newContentDecompressor(AsciiString contentEncoding) throws Http2Exception {
if (HttpHeaderValues.GZIP.equalsIgnoreCase(contentEncoding) ||
HttpHeaderValues.X_GZIP.equalsIgnoreCase(contentEncoding)) {
X_GZIP.equalsIgnoreCase(contentEncoding)) {
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
if (HttpHeaderValues.DEFLATE.equalsIgnoreCase(contentEncoding) ||
HttpHeaderValues.X_DEFLATE.equalsIgnoreCase(contentEncoding)) {
X_DEFLATE.equalsIgnoreCase(contentEncoding)) {
final ZlibWrapper wrapper = strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(wrapper));