joerghoh commented on code in PR #106:
URL:
https://github.com/apache/sling-org-apache-sling-engine/pull/106#discussion_r4548989132
##########
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 think that we can serve HTML when the user-agent explicitly asks for it.
So do not deliver HTML when ``*/*`` is specified (in that case the server is
free choose the format).
--
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]