Support for empty HTTP request header values.

This commit is contained in:
Daniel Bevenius 2013-11-17 12:22:06 +01:00 committed by Norman Maurer
parent 6ba1a85c4b
commit 624573971f
2 changed files with 19 additions and 1 deletions

View File

@ -736,7 +736,12 @@ public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
sb.setLength(end);
}
headers.add(name, sb.toString());
String value = sb.toString();
if (value.length() == 1 && value.equals("\r")) {
headers.add(name, "");
} else {
headers.add(name, value);
}
parseState = HeaderParseState.LINE_START;
// unread one byte to process it in LINE_START

View File

@ -19,6 +19,7 @@ package io.netty.handler.codec.http;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
@ -159,4 +160,16 @@ public class HttpRequestDecoderTest {
Assert.assertFalse(channel.finish());
Assert.assertNull(channel.readInbound());
}
@Test
public void testEmptyHeaderValue() {
EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder());
String crlf = "\r\n";
String request = "GET /some/path HTTP/1.1" + crlf +
"Host: localhost" + crlf +
"EmptyHeader:" + crlf + crlf;
channel.writeInbound(Unpooled.wrappedBuffer(request.getBytes(CharsetUtil.US_ASCII)));
HttpRequest req = (HttpRequest) channel.readInbound();
Assert.assertEquals("", req.headers().get("EmptyHeader"));
}
}