452424 Do not add Date header if already set
This commit is contained in:
parent
46a5ef861d
commit
1915e592b5
|
@ -171,6 +171,17 @@ public class HttpFields implements Iterable<HttpField>
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean contains(HttpHeader header)
|
||||
{
|
||||
for (int i=0;i<_fields.size();i++)
|
||||
{
|
||||
HttpField f=_fields.get(i);
|
||||
if (f.getHeader()==header)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean containsKey(String name)
|
||||
{
|
||||
|
@ -182,7 +193,8 @@ public class HttpFields implements Iterable<HttpField>
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getStringField(HttpHeader header)
|
||||
{
|
||||
return getStringField(header.asString());
|
||||
|
|
|
@ -656,19 +656,20 @@ public class HttpChannel<T> implements HttpParser.RequestHandler<T>, Runnable, H
|
|||
public boolean headerComplete()
|
||||
{
|
||||
_requests.incrementAndGet();
|
||||
HttpFields fields = _response.getHttpFields();
|
||||
switch (_version)
|
||||
{
|
||||
case HTTP_0_9:
|
||||
break;
|
||||
|
||||
case HTTP_1_0:
|
||||
if (_configuration.getSendDateHeader())
|
||||
_response.getHttpFields().put(_connector.getServer().getDateField());
|
||||
if (_configuration.getSendDateHeader() && !fields.contains(HttpHeader.DATE))
|
||||
_response.getHttpFields().add(_connector.getServer().getDateField());
|
||||
break;
|
||||
|
||||
case HTTP_1_1:
|
||||
if (_configuration.getSendDateHeader())
|
||||
_response.getHttpFields().put(_connector.getServer().getDateField());
|
||||
if (_configuration.getSendDateHeader() && !fields.contains(HttpHeader.DATE))
|
||||
_response.getHttpFields().add(_connector.getServer().getDateField());
|
||||
|
||||
if (_expect)
|
||||
{
|
||||
|
|
|
@ -81,6 +81,9 @@ public class DumpHandler extends AbstractHandler
|
|||
read.append((char)in.read());
|
||||
}
|
||||
|
||||
if (request.getParameter("date")!=null)
|
||||
response.setHeader("Date",request.getParameter("date"));
|
||||
|
||||
if (request.getParameter("ISE")!=null)
|
||||
{
|
||||
throw new IllegalStateException("Testing ISE");
|
||||
|
|
|
@ -73,6 +73,7 @@ public class HttpConnectionTest
|
|||
|
||||
connector = new LocalConnector(server,http,null);
|
||||
connector.setIdleTimeout(5000);
|
||||
connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setSendDateHeader(true);
|
||||
server.addConnector(connector);
|
||||
server.setHandler(new DumpHandler());
|
||||
ErrorHandler eh=new ErrorHandler();
|
||||
|
@ -146,6 +147,34 @@ public class HttpConnectionTest
|
|||
checkContains(response,offset,"pathInfo=/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDate() throws Exception
|
||||
{
|
||||
String response=connector.getResponses("GET / HTTP/1.1\n"+
|
||||
"Host: localhost:80\n"+
|
||||
"Connection: close\n"+
|
||||
"\n");
|
||||
|
||||
int offset=0;
|
||||
offset = checkContains(response,offset,"HTTP/1.1 200");
|
||||
offset = checkContains(response,offset,"Date: ");
|
||||
checkContains(response,offset,"pathInfo=/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetDate() throws Exception
|
||||
{
|
||||
String response=connector.getResponses("GET /?date=1+Jan+1970 HTTP/1.1\n"+
|
||||
"Host: localhost:80\n"+
|
||||
"Connection: close\n"+
|
||||
"\n");
|
||||
|
||||
int offset=0;
|
||||
offset = checkContains(response,offset,"HTTP/1.1 200");
|
||||
offset = checkContains(response,offset,"Date: 1 Jan 1970");
|
||||
checkContains(response,offset,"pathInfo=/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBadNoPath() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue