416015 Handle null Accept-Language and other headers

This commit is contained in:
Greg Wilkins 2013-09-09 16:51:37 +10:00
parent 767faece5c
commit e2e1b47edf
2 changed files with 40 additions and 2 deletions

View File

@ -445,7 +445,7 @@ public class HttpFields implements Iterable<HttpField>
{
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<String>()
@ -461,7 +461,7 @@ public class HttpFields implements Iterable<HttpField>
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;

View File

@ -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
{