Port the changes in SpdyHeaderBlockRawDecoder to master & 4.0

Somehow it slipped away.
This commit is contained in:
Trustin Lee 2014-01-13 23:07:51 +09:00
parent ad70e69e47
commit 1a54ff843c

View File

@ -21,34 +21,27 @@ import static io.netty.handler.codec.spdy.SpdyCodecUtil.*;
public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder { public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder {
private static final int LENGTH_FIELD_SIZE = 4;
private final int version; private final int version;
private final int maxHeaderSize; private final int maxHeaderSize;
private final int lengthFieldSize;
// Header block decoding fields // Header block decoding fields
private int headerSize; private int headerSize;
private int numHeaders; private int numHeaders = -1;
public SpdyHeaderBlockRawDecoder(SpdyVersion version, int maxHeaderSize) { public SpdyHeaderBlockRawDecoder(SpdyVersion spdyVersion, int maxHeaderSize) {
if (version == null) { if (spdyVersion == null) {
throw new NullPointerException("version"); throw new NullPointerException("spdyVersion");
} }
this.version = version.getVersion(); version = spdyVersion.getVersion();
this.maxHeaderSize = maxHeaderSize; this.maxHeaderSize = maxHeaderSize;
lengthFieldSize = this.version < 3 ? 2 : 4;
reset();
} }
private int readLengthField(ByteBuf buffer) { private static int readLengthField(ByteBuf buffer) {
int length; int length = getSignedInt(buffer, buffer.readerIndex());
if (version < 3) { buffer.skipBytes(LENGTH_FIELD_SIZE);
length = getUnsignedShort(buffer, buffer.readerIndex());
buffer.skipBytes(2);
} else {
length = getSignedInt(buffer, buffer.readerIndex());
buffer.skipBytes(4);
}
return length; return length;
} }
@ -63,7 +56,7 @@ public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder {
if (numHeaders == -1) { if (numHeaders == -1) {
// Read number of Name/Value pairs // Read number of Name/Value pairs
if (encoded.readableBytes() < lengthFieldSize) { if (encoded.readableBytes() < LENGTH_FIELD_SIZE) {
return; return;
} }
numHeaders = readLengthField(encoded); numHeaders = readLengthField(encoded);
@ -78,7 +71,7 @@ public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder {
encoded.markReaderIndex(); encoded.markReaderIndex();
// Try to read length of name // Try to read length of name
if (encoded.readableBytes() < lengthFieldSize) { if (encoded.readableBytes() < LENGTH_FIELD_SIZE) {
encoded.resetReaderIndex(); encoded.resetReaderIndex();
return; return;
} }
@ -111,7 +104,7 @@ public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder {
} }
// Try to read length of value // Try to read length of value
if (encoded.readableBytes() < lengthFieldSize) { if (encoded.readableBytes() < LENGTH_FIELD_SIZE) {
encoded.resetReaderIndex(); encoded.resetReaderIndex();
return; return;
} }
@ -125,15 +118,10 @@ public class SpdyHeaderBlockRawDecoder extends SpdyHeaderBlockDecoder {
// SPDY/3 allows zero-length (empty) header values // SPDY/3 allows zero-length (empty) header values
if (valueLength == 0) { if (valueLength == 0) {
if (version < 3) { frame.headers().add(name, "");
frame.setInvalid(); numHeaders --;
return; this.headerSize = headerSize;
} else { continue;
frame.headers().add(name, "");
numHeaders --;
this.headerSize = headerSize;
continue;
}
} }
headerSize += valueLength; headerSize += valueLength;