Merge remote-tracking branch 'origin/jetty-9.3.x'

This commit is contained in:
Greg Wilkins 2016-03-05 11:06:34 +01:00
commit 692aae0d3e
3 changed files with 53 additions and 15 deletions

View File

@ -1174,7 +1174,7 @@ public class HttpParser
{
_value=null;
_string.setLength(0);
_valueString=null;
_valueString=_compliance.ordinal()<=HttpCompliance.RFC2616.ordinal()?"":null;
_length=-1;
setState(State.HEADER);

View File

@ -260,7 +260,7 @@ public class HttpParserTest
"\015\012");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser= new HttpParser(handler,4096,HttpCompliance.RFC2616);
HttpParser parser= new HttpParser(handler,HttpCompliance.RFC2616);
parseAll(parser,buffer);
Assert.assertThat(_bad,Matchers.nullValue());
@ -336,7 +336,38 @@ public class HttpParserTest
@Test
public void testNoValue() throws Exception
public void test2616NoValue() throws Exception
{
ByteBuffer buffer= BufferUtil.toBuffer(
"GET / HTTP/1.0\015\012" +
"Host: localhost\015\012" +
"Name0: \015\012"+
"Name1: \015\012"+
"Connection: close\015\012" +
"\015\012");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser= new HttpParser(handler,HttpCompliance.RFC2616);
parseAll(parser,buffer);
assertTrue(_headerCompleted);
assertTrue(_messageCompleted);
assertEquals("GET", _methodOrVersion);
assertEquals("/", _uriOrStatus);
assertEquals("HTTP/1.0", _versionOrReason);
assertEquals("Host", _hdr[0]);
assertEquals("localhost", _val[0]);
assertEquals("Name0", _hdr[1]);
assertEquals("", _val[1]);
assertEquals("Name1", _hdr[2]);
assertEquals("", _val[2]);
assertEquals("Connection", _hdr[3]);
assertEquals("close", _val[3]);
assertEquals(3, _headers);
}
@Test
public void test7230NoValue() throws Exception
{
ByteBuffer buffer= BufferUtil.toBuffer(
"GET / HTTP/1.0\015\012" +

View File

@ -30,6 +30,7 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
@ -132,18 +133,24 @@ public class ErrorHandler extends AbstractHandler
baseRequest.setHandled(true);
response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
if (_cacheControl!=null)
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
String reason=(response instanceof Response)?((Response)response).getReason():null;
if (LOG.isDebugEnabled())
LOG.debug("default error page {} {}",request,response);
handleErrorPage(request, writer, response.getStatus(), reason);
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
// Issue #124 - Don't produce text/html if the request doesn't accept it
HttpField accept = baseRequest.getHttpFields().getField(HttpHeader.ACCEPT);
if (accept == null || accept.contains("text/html") || accept.contains("*/*"))
{
response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
if (_cacheControl != null)
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(4096);
String reason = (response instanceof Response) ? ((Response) response).getReason() : null;
if (LOG.isDebugEnabled())
LOG.debug("default error page {} {}",request,response);
handleErrorPage(request, writer, response.getStatus(), reason);
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
}
}
/* ------------------------------------------------------------ */