From ceb06dc1b15494e9e5298afb89bdd728e3397e4e Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Sat, 1 Nov 2014 02:51:34 +0900 Subject: [PATCH] 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. --- .../codec/http/HttpContentDecompressor.java | 14 ++++++++++++-- .../netty/handler/codec/http/HttpHeaderValues.java | 8 -------- .../http2/DelegatingDecompressorFrameListener.java | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecompressor.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecompressor.java index c3c2ffdd64..45344677cd 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecompressor.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpContentDecompressor.java @@ -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)); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderValues.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderValues.java index a5a27cc11b..ea907cba2b 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderValues.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpHeaderValues.java @@ -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() { } } diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java index fdeaeb40d5..bdb0c4a019 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DelegatingDecompressorFrameListener.java @@ -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));