From 0e2472b8e1eda932e1f9a3ee0cffcd2aed105800 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 22 Mar 2016 11:20:50 -0700 Subject: [PATCH] Issue #451 - RFC2616 Compliance mode should support empty headers Updating test cases to show empty quoted header quirk --- .../eclipse/jetty/http/HttpParserTest.java | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java index 9f6f54b64b6..581123f2224 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java @@ -18,9 +18,6 @@ package org.eclipse.jetty.http; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; - import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -33,6 +30,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import static org.hamcrest.Matchers.containsString; +import static org.junit.Assert.assertThat; + public class HttpParserTest { /** @@ -351,6 +351,56 @@ public class HttpParserTest Assert.assertEquals(2, _headers); } + @Test + public void testEmptyQuotedValue2616() throws Exception + { + ByteBuffer buffer = BufferUtil.toBuffer( + "GET / HTTP/1.0\r\n" + + "Host: localhost\r\n" + + "Name0: \"\"\r\n" + + "\r\n"); + + HttpParser.RequestHandler handler = new Handler(); + HttpParser parser = new HttpParser(handler, HttpCompliance.RFC2616); + parseAll(parser, buffer); + + Assert.assertTrue(_headerCompleted); + Assert.assertTrue(_messageCompleted); + Assert.assertEquals("GET", _methodOrVersion); + Assert.assertEquals("/", _uriOrStatus); + Assert.assertEquals("HTTP/1.0", _versionOrReason); + Assert.assertEquals("Host", _hdr[0]); + Assert.assertEquals("localhost", _val[0]); + Assert.assertEquals("Name0", _hdr[1]); + Assert.assertEquals("", _val[1]); + Assert.assertEquals(2, _headers); + } + + @Test + public void testEmptyQuotedValue7230() throws Exception + { + ByteBuffer buffer = BufferUtil.toBuffer( + "GET / HTTP/1.0\r\n" + + "Host: localhost\r\n" + + "Name0: \"\"\r\n" + + "\r\n"); + + HttpParser.RequestHandler handler = new Handler(); + HttpParser parser = new HttpParser(handler, HttpCompliance.RFC7230); + parseAll(parser, buffer); + + Assert.assertTrue(_headerCompleted); + Assert.assertTrue(_messageCompleted); + Assert.assertEquals("GET", _methodOrVersion); + Assert.assertEquals("/", _uriOrStatus); + Assert.assertEquals("HTTP/1.0", _versionOrReason); + Assert.assertEquals("Host", _hdr[0]); + Assert.assertEquals("localhost", _val[0]); + Assert.assertEquals("Name0", _hdr[1]); + Assert.assertEquals("", _val[1]); + Assert.assertEquals(2, _headers); + } + @Test public void testNoColon2616() throws Exception {