This commit is contained in:
Greg Wilkins 2016-07-20 16:59:28 +10:00
parent d6c73118be
commit 7e16731b9d
6 changed files with 47 additions and 9 deletions

View File

@ -907,7 +907,7 @@ public class HttpParser
case HOST:
_host=true;
if (!(_field instanceof HostPortHttpField))
if (!(_field instanceof HostPortHttpField) && _valueString!=null && !_valueString.isEmpty())
{
_field=new HostPortHttpField(_header,legacyString(_headerString,_header.asString()),_valueString);
add_to_connection_trie=_connectionFields!=null;

View File

@ -1707,6 +1707,21 @@ public class HttpParserTest
Assert.assertEquals(8888, _port);
}
@Test
public void testEmptyHostPort() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host:\r\n"
+ "Connection: close\r\n"
+ "\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.parseNext(buffer);
Assert.assertEquals(null, _host);
Assert.assertEquals(null, _bad);
}
@Test
public void testCachedField() throws Exception
{

View File

@ -1360,12 +1360,14 @@ public class Request implements HttpServletRequest
HttpField host = metadata==null?null:metadata.getFields().getField(HttpHeader.HOST);
if (host!=null)
{
// TODO is this needed now?
HostPortHttpField authority = (host instanceof HostPortHttpField)
?((HostPortHttpField)host)
:new HostPortHttpField(host.getValue());
metadata.getURI().setAuthority(authority.getHost(),authority.getPort());
return authority.getHost();
if (!(host instanceof HostPortHttpField) && host.getValue()!=null && !host.getValue().isEmpty())
host=new HostPortHttpField(host.getValue());
if (host instanceof HostPortHttpField)
{
HostPortHttpField authority = (HostPortHttpField)host;
metadata.getURI().setAuthority(authority.getHost(),authority.getPort());
return authority.getHost();
}
}
// Return host from connection

View File

@ -392,6 +392,27 @@ public class HttpConnectionTest
checkContains(response,0,"HTTP/1.1 400");
}
@Test
public void testNoHost() throws Exception
{
String response;
response=connector.getResponse("GET / HTTP/1.1\r\n"+
"\r\n");
checkContains(response,0,"HTTP/1.1 400");
}
@Test
public void testEmptyHost() throws Exception
{
String response;
response=connector.getResponse("GET / HTTP/1.1\r\n"+
"Host:\r\n"+
"\r\n");
checkContains(response,0,"HTTP/1.1 200");
}
@Test
public void testBadURIencoding() throws Exception
{

View File

@ -553,7 +553,7 @@ public class PartialRFC2616Test
offset=0;
response=connector.getResponses("GET /R1 HTTP/1.1\n"+"Host:\n"+"Connection: close\n"+"\n");
offset=checkContains(response,offset,"HTTP/1.1 400","400")+1;
offset=checkContains(response,offset,"HTTP/1.1 200","200")+1;
}
}

View File

@ -1459,7 +1459,7 @@ public abstract class RFC2616BaseTest
req4.append("\n");
HttpTester.Response response = http.request(req4);
assertEquals("14.23 HTTP/1.1 - Empty Host", HttpStatus.BAD_REQUEST_400, response.getStatus());
assertEquals("14.23 HTTP/1.1 - Empty Host", HttpStatus.OK_200, response.getStatus());
}
}