cziegeler commented on code in PR #106:
URL: 
https://github.com/apache/sling-org-apache-sling-engine/pull/106#discussion_r4548755136


##########
src/main/java/org/apache/sling/engine/impl/DefaultErrorHandler.java:
##########
@@ -133,6 +150,27 @@ private void delegateFailed(
         sendError(originalStatus, originalMessage, null, request, response);
     }
 
+    protected JakartaErrorHandler getErrorHandler(final 
SlingJakartaHttpServletRequest request) {
+        final JakartaErrorHandler nonHtml = this.nonHtmlDelegate;
+        if (this.enableAcceptHeaderCheck && nonHtml != null && 
!acceptsHtml(request)) {
+            return nonHtml;
+        }
+        return this.delegate;
+    }
+
+    /**
+     * A request is treated as HTML if its Accept header matches {@code 
text/html},
+     * including through {@code text/*}, and does not contain {@code *}{@code 
/*}.
+     * A missing or blank Accept header, or any header containing {@code 
*}{@code /*},
+     * is treated as non-HTML, even if it also explicitly accepts {@code 
text/html}.
+     * Only the accept header is evaluated: request parameters are not read, 
as parameter
+     * parsing might itself be the cause of the error being handled.
+     */
+    private static boolean acceptsHtml(final SlingJakartaHttpServletRequest 
request) {
+        final JakartaMediaRangeList acceptList = 
JakartaMediaRangeList.fromRequest(request);
+        return !acceptList.matchesAll() && 
acceptList.prefer(JakartaMediaRangeList.CONTENT_TYPE_HTML) != null;

Review Comment:
   Lets not talk about method names or the javadoc - but the functionality. 
When do we want to generate a html response? If the client says, I accept 
everything? If the client says, I accept everything but also text/html ?
   I think the answer for the first case is a clear no. For the second case we 
can argue either way. I would still consider this a no. If a client really 
wants html it should not use an accept all wildcard.



-- 
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