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:
parent
f793f395d6
commit
ceb06dc1b1
@ -16,6 +16,7 @@
|
|||||||
package io.netty.handler.codec.http;
|
package io.netty.handler.codec.http;
|
||||||
|
|
||||||
import io.netty.channel.embedded.EmbeddedChannel;
|
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.ZlibCodecFactory;
|
||||||
import io.netty.handler.codec.compression.ZlibWrapper;
|
import io.netty.handler.codec.compression.ZlibWrapper;
|
||||||
|
|
||||||
@ -26,6 +27,15 @@ import io.netty.handler.codec.compression.ZlibWrapper;
|
|||||||
*/
|
*/
|
||||||
public class HttpContentDecompressor extends HttpContentDecoder {
|
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;
|
private final boolean strict;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,11 +58,11 @@ public class HttpContentDecompressor extends HttpContentDecoder {
|
|||||||
@Override
|
@Override
|
||||||
protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception {
|
protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception {
|
||||||
if (HttpHeaderValues.GZIP.equalsIgnoreCase(contentEncoding) ||
|
if (HttpHeaderValues.GZIP.equalsIgnoreCase(contentEncoding) ||
|
||||||
HttpHeaderValues.X_GZIP.equalsIgnoreCase(contentEncoding)) {
|
X_GZIP.equalsIgnoreCase(contentEncoding)) {
|
||||||
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
|
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
|
||||||
}
|
}
|
||||||
if (HttpHeaderValues.DEFLATE.equalsIgnoreCase(contentEncoding) ||
|
if (HttpHeaderValues.DEFLATE.equalsIgnoreCase(contentEncoding) ||
|
||||||
HttpHeaderValues.X_DEFLATE.equalsIgnoreCase(contentEncoding)) {
|
X_DEFLATE.equalsIgnoreCase(contentEncoding)) {
|
||||||
final ZlibWrapper wrapper = strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
|
final ZlibWrapper wrapper = strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
|
||||||
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
|
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
|
||||||
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(wrapper));
|
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(wrapper));
|
||||||
|
@ -188,14 +188,6 @@ public final class HttpHeaderValues {
|
|||||||
* {@code "websocket"}
|
* {@code "websocket"}
|
||||||
*/
|
*/
|
||||||
public static final AsciiString WEBSOCKET = new AsciiString("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() { }
|
private HttpHeaderValues() { }
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,16 @@ import io.netty.handler.codec.http.HttpHeaderValues;
|
|||||||
* stream.
|
* stream.
|
||||||
*/
|
*/
|
||||||
public class DelegatingDecompressorFrameListener extends Http2FrameListenerDecorator {
|
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() {
|
private static final Http2ConnectionAdapter CLEAN_UP_LISTENER = new Http2ConnectionAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void streamRemoved(Http2Stream stream) {
|
public void streamRemoved(Http2Stream stream) {
|
||||||
@ -121,11 +131,11 @@ public class DelegatingDecompressorFrameListener extends Http2FrameListenerDecor
|
|||||||
*/
|
*/
|
||||||
protected EmbeddedChannel newContentDecompressor(AsciiString contentEncoding) throws Http2Exception {
|
protected EmbeddedChannel newContentDecompressor(AsciiString contentEncoding) throws Http2Exception {
|
||||||
if (HttpHeaderValues.GZIP.equalsIgnoreCase(contentEncoding) ||
|
if (HttpHeaderValues.GZIP.equalsIgnoreCase(contentEncoding) ||
|
||||||
HttpHeaderValues.X_GZIP.equalsIgnoreCase(contentEncoding)) {
|
X_GZIP.equalsIgnoreCase(contentEncoding)) {
|
||||||
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
|
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
|
||||||
}
|
}
|
||||||
if (HttpHeaderValues.DEFLATE.equalsIgnoreCase(contentEncoding) ||
|
if (HttpHeaderValues.DEFLATE.equalsIgnoreCase(contentEncoding) ||
|
||||||
HttpHeaderValues.X_DEFLATE.equalsIgnoreCase(contentEncoding)) {
|
X_DEFLATE.equalsIgnoreCase(contentEncoding)) {
|
||||||
final ZlibWrapper wrapper = strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
|
final ZlibWrapper wrapper = strict ? ZlibWrapper.ZLIB : ZlibWrapper.ZLIB_OR_NONE;
|
||||||
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
|
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
|
||||||
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(wrapper));
|
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(wrapper));
|
||||||
|
Loading…
Reference in New Issue
Block a user