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


##########
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:
   @joerghoh Depends, CLI tools, self built clients often send a wildcard 
accept - do we want to assume that they always ask for html? if so, the above 
logic needs to be changed.
   If you have suggestions on how to make this correct, please just apply and 
update the test cases



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