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:
Joakim Erdfelt 2016-03-02 17:10:50 -07:00
parent 8f8fcd1b1a
commit a7be6bc8ea
1 changed files with 16 additions and 10 deletions

View File

@ -110,16 +110,22 @@ public class ErrorHandler extends AbstractHandler
} }
baseRequest.setHandled(true); baseRequest.setHandled(true);
response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
if (_cacheControl!=null) // Issue #124 - Don't produce text/html if the request doesn't accept it
response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl); String reqAccept = request.getHeader("Accept");
ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096); if (reqAccept == null || reqAccept.contains("text/html") || reqAccept.contains("*/*"))
String reason=(response instanceof Response)?((Response)response).getReason():null; {
handleErrorPage(request, writer, response.getStatus(), reason); response.setContentType(MimeTypes.Type.TEXT_HTML_8859_1.asString());
writer.flush(); if (_cacheControl != null)
response.setContentLength(writer.size()); response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
writer.writeTo(response.getOutputStream()); ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(4096);
writer.destroy(); String reason = (response instanceof Response) ? ((Response) response).getReason() : null;
handleErrorPage(request, writer, response.getStatus(), reason);
writer.flush();
response.setContentLength(writer.size());
writer.writeTo(response.getOutputStream());
writer.destroy();
}
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */