diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java index 3f2c12d80a0..58f95577091 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java @@ -445,7 +445,7 @@ public class HttpFields implements Iterable { final HttpField f = _fields.get(i); - if (f.getName().equalsIgnoreCase(name)) + if (f.getName().equalsIgnoreCase(name) && f.getValue()!=null) { final int first=i; return new Enumeration() @@ -461,7 +461,7 @@ public class HttpFields implements Iterable while (i<_fields.size()) { field=_fields.get(i++); - if (field.getName().equalsIgnoreCase(name)) + if (field.getName().equalsIgnoreCase(name) && field.getValue()!=null) return true; } field=null; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index a731c421143..c8878767132 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Map; import java.util.concurrent.TimeUnit; + import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; import javax.servlet.ServletRequestEvent; @@ -49,6 +50,7 @@ import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.StdErrLog; import org.hamcrest.Matchers; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -56,6 +58,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; @@ -122,6 +125,41 @@ public class RequestTest } + @Test + public void testEmptyHeaders() throws Exception + { + _handler._checker = new RequestTester() + { + @Override + public boolean check(HttpServletRequest request,HttpServletResponse response) + { + assertNotNull(request.getLocale()); + assertTrue(request.getLocales().hasMoreElements()); + assertNull(request.getContentType()); + assertNull(request.getCharacterEncoding()); + assertEquals(0,request.getQueryString().length()); + assertEquals(-1,request.getContentLength()); + assertEquals(0,request.getCookies().length); + assertNull(request.getHeader("Name")); + assertFalse(request.getHeaders("Name").hasMoreElements()); + assertEquals(-1,request.getDateHeader("Name")); + return true; + } + }; + + String request="GET /? HTTP/1.1\r\n"+ + "Host: whatever\r\n"+ + "Connection: close\n"+ + "Content-Type: \n"+ + "Accept-Language: \n"+ + "Cookie: \n"+ + "Name: \n"+ + "\n"; + + String responses=_connector.getResponses(request); + assertTrue(responses.startsWith("HTTP/1.1 200")); + } + @Test public void testMultiPartNoConfig() throws Exception {