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


##########
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:
   I understand the description in this way: Returns true if the user-agent 
accepts HTML.
   
   The expression:
   ``
   return !acceptList.matchesAll() && 
acceptList.prefer(JakartaMediaRangeList.CONTENT_TYPE_HTML) != null;
   ``
   
   | accept header contains ``*/*`` | accept has a preference for HTML | result 
of the expression | Note |
   --- | --- | --- | --- |
   | true | true | false | **Incorrect**, the request cannot indicate more 
clear that it accepts HTML |
   | true | false | false | **Incorrect**
   | false | true | true | Correct
   | false | false | false | Correct
   
   For that either the expression is incorrect or the javadoc misleading.
   



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