Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 96C87974C for ; Tue, 21 Feb 2012 13:02:23 +0000 (UTC) Received: (qmail 82707 invoked by uid 500); 21 Feb 2012 13:02:23 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 82627 invoked by uid 500); 21 Feb 2012 13:02:22 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 82612 invoked by uid 99); 21 Feb 2012 13:02:22 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Feb 2012 13:02:22 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Feb 2012 13:02:21 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id A2B1F23888CD; Tue, 21 Feb 2012 13:02:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1291754 - /sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java Date: Tue, 21 Feb 2012 13:02:01 -0000 To: commits@sling.apache.org From: fmeschbe@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120221130201.A2B1F23888CD@eris.apache.org> Author: fmeschbe Date: Tue Feb 21 13:02:01 2012 New Revision: 1291754 URL: http://svn.apache.org/viewvc?rev=1291754&view=rev Log: SLING-2424 Only set the default response content type and character encoding if not included Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java?rev=1291754&r1=1291753&r2=1291754&view=diff ============================================================================== --- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java (original) +++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/DefaultSlingScript.java Tue Feb 21 13:02:01 2012 @@ -57,6 +57,7 @@ import javax.servlet.ServletContext; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; +import org.apache.sling.api.SlingConstants; import org.apache.sling.api.SlingException; import org.apache.sling.api.SlingHttpServletRequest; import org.apache.sling.api.SlingHttpServletResponse; @@ -85,9 +86,9 @@ class DefaultSlingScript implements Slin private static ThreadLocal requestResourceResolver = new ThreadLocal(); /** The set of protected keys. */ - private static final Set PROTECTED_KEYS = + private static final Set PROTECTED_KEYS = new HashSet(Arrays.asList(REQUEST, RESPONSE, READER, SLING, RESOURCE, OUT, LOG)); - + /** The resource pointing to the script. */ private final Resource scriptResource; @@ -436,20 +437,22 @@ class DefaultSlingScript implements Slin props.setRequest((SlingHttpServletRequest) req); props.setResponse((SlingHttpServletResponse) res); - // try to set content type - final String contentType = request.getResponseContentType(); - if (contentType != null) { - res.setContentType(contentType); - - // only set the character encoding for text/ content types - // see SLING-679 - if (contentType.startsWith("text/")) { - res.setCharacterEncoding("UTF-8"); + // try to set content type (unless included) + if (request.getAttribute(SlingConstants.ATTR_INCLUDE_SERVLET_PATH) == null) { + final String contentType = request.getResponseContentType(); + if (contentType != null) { + res.setContentType(contentType); + + // only set the character encoding for text/ content types + // see SLING-679 + if (contentType.startsWith("text/")) { + res.setCharacterEncoding("UTF-8"); + } + } else { + LOGGER.debug("service: No response content type defined for request {}.", request.getRequestURI()); } } else { - LOGGER.debug( - "service:No response content type defined for request {}.", - request.getRequestURI()); + LOGGER.debug("service: Included request, not setting content type and encoding"); } // evaluate the script now using the ScriptEngine @@ -682,7 +685,7 @@ class DefaultSlingScript implements Slin if (!bindingsValuesProviders.isEmpty()) { Set protectedKeys = new HashSet(); protectedKeys.addAll(PROTECTED_KEYS); - + ProtectedBindings protectedBindings = new ProtectedBindings(bindings, protectedKeys); for (BindingsValuesProvider provider : bindingsValuesProviders) { provider.addBindings(protectedBindings);