cziegeler commented on code in PR #78:
URL: 
https://github.com/apache/sling-org-apache-sling-servlets-resolver/pull/78#discussion_r4525666469


##########
src/main/java/org/apache/sling/servlets/resolver/internal/defaults/DefaultErrorHandlerServlet.java:
##########
@@ -77,14 +80,25 @@ public void service(ServletRequest req, ServletResponse 
res) throws IOException
             statusMessage = statusToString(statusCode);
         }
 
-        // properly consider the 'Accept' header conditions to decide whether 
to send json or html back
-        if (req instanceof HttpServletRequest
-                && JSON_CONTENT_TYPE.equals(new 
JakartaMediaRangeList((HttpServletRequest) req)
-                        .prefer(HTML_CONTENT_TYPE, JSON_CONTENT_TYPE))) {
+        // parse the accept header to retrieve the preferred content-type and 
decide on the error handler
+        String contentType = HTML_CONTENT_TYPE;
+        if (req instanceof HttpServletRequest) {
+            contentType =
+                    new JakartaMediaRangeList((HttpServletRequest) 
req).prefer(HTML_CONTENT_TYPE, JSON_CONTENT_TYPE);
+        }
+
+        if (JSON_CONTENT_TYPE.equals(contentType)) {
             renderJson(req, res, statusMessage, requestUri, servletName, 
statusCode);
-        } else {
-            // default to HTML rendering
+        } else if (HTML_CONTENT_TYPE.equals(contentType)) {
             renderHtml(req, res, statusMessage, requestUri, servletName, 
statusCode);
+        } else if (!res.isCommitted()) {
+            // for all non-committed requests which are not JSON or HTML just 
clear the buffer and set the
+            // statuscode; do not output anything.
+            res.resetBuffer();
+            ((HttpServletResponse) res).setStatus(statusCode);
+            res.setContentLength(0);

Review Comment:
   No :) reset() would clean out everything set by error filters and the header 
pre-serving configuration in Sling Engine



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to