More robust CR/LF handling in chunked encoding

This commit is contained in:
Trustin Lee 2009-02-12 05:48:25 +00:00
parent 9125ff5616
commit a4fe52559b

View File

@ -129,14 +129,19 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
readChunkedContent(channel, buffer); readChunkedContent(channel, buffer);
} }
case READ_CHUNK_DELIMITER: { case READ_CHUNK_DELIMITER: {
// FIXME: LF should be skipped, too. (check the whole codec) for (;;) {
byte next = buffer.readByte(); byte next = buffer.readByte();
if (next == HttpCodecUtil.CR) { if (next == HttpCodecUtil.CR) {
buffer.readByte(); if (buffer.readByte() == HttpCodecUtil.LF) {
}
checkpoint(State.READ_CHUNK_SIZE); checkpoint(State.READ_CHUNK_SIZE);
return null; return null;
} }
} else if (next == HttpCodecUtil.LF) {
checkpoint(State.READ_CHUNK_SIZE);
return null;
}
}
}
case READ_CHUNK_FOOTER: { case READ_CHUNK_FOOTER: {
String line = readIntoCurrentLine(buffer); String line = readIntoCurrentLine(buffer);
if (line.trim().length() == 0) { if (line.trim().length() == 0) {
@ -235,12 +240,12 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
return Integer.parseInt(hex, 16); return Integer.parseInt(hex, 16);
} }
protected String readIntoCurrentLine(ChannelBuffer channel) { protected String readIntoCurrentLine(ChannelBuffer buffer) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
while (true) { while (true) {
byte nextByte = channel.readByte(); byte nextByte = buffer.readByte();
if (nextByte == HttpCodecUtil.CR) { if (nextByte == HttpCodecUtil.CR) {
nextByte = channel.readByte(); nextByte = buffer.readByte();
if (nextByte == HttpCodecUtil.LF) { if (nextByte == HttpCodecUtil.LF) {
return sb.toString(); return sb.toString();
} }