Issue #124 - Don't produce text/html if the request doesn't accept it
+ If request has no 'Accept' header, produce text/html as before. + If request has 'Accept' header, then test for 'text/html' or '*/*' entries before producing html output. Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
8f8fcd1b1a
commit
a7be6bc8ea
|
@ -110,17 +110,23 @@ public class ErrorHandler extends AbstractHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
|
|
||||||
|
// Issue #124 - Don't produce text/html if the request doesn't accept it
|
||||||
|
String reqAccept = request.getHeader("Accept");
|
||||||
|
if (reqAccept == null || reqAccept.contains("text/html") || reqAccept.contains("*/*"))
|
||||||
|
{
|
||||||
response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
|
response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
|
||||||
if (_cacheControl!=null)
|
if (_cacheControl != null)
|
||||||
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
|
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
|
||||||
ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
|
ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(4096);
|
||||||
String reason=(response instanceof Response)?((Response)response).getReason():null;
|
String reason = (response instanceof Response) ? ((Response) response).getReason() : null;
|
||||||
handleErrorPage(request, writer, response.getStatus(), reason);
|
handleErrorPage(request, writer, response.getStatus(), reason);
|
||||||
writer.flush();
|
writer.flush();
|
||||||
response.setContentLength(writer.size());
|
response.setContentLength(writer.size());
|
||||||
writer.writeTo(response.getOutputStream());
|
writer.writeTo(response.getOutputStream());
|
||||||
writer.destroy();
|
writer.destroy();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
protected void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message)
|
protected void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message)
|
||||||
|
|
Loading…
Reference in New Issue