Support for empty HTTP request header values.
This commit is contained in:
parent
6ba1a85c4b
commit
624573971f
@ -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
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user