[ https://issues.apache.org/jira/browse/FREEMARKER-1?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14953120#comment-14953120 ]
ASF GitHub Bot commented on FREEMARKER-1: ----------------------------------------- GitHub user woonsan opened a pull request: https://github.com/apache/incubator-freemarker/pull/5 FREEMARKER-1 adding OverrideResponseContentType init param in FreemarkerServlet You can merge this pull request into a Git repository by running: $ git pull https://github.com/woonsan/incubator-freemarker feature/FREEMARKER-1-option-overrideResponseContentType-on-2.3-gae Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-freemarker/pull/5.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #5 ---- commit e89dbfce5f2d2274653062dfd6911a62c354c39b Author: Woonsan Ko <woon...@apache.org> Date: 2015-10-12T13:31:16Z FREEMARKER-1 adding OverrideResponseContentType init param in FreemarketServlet ---- > Option to not to overwrite response ContentType in FreemarkerServlet > -------------------------------------------------------------------- > > Key: FREEMARKER-1 > URL: https://issues.apache.org/jira/browse/FREEMARKER-1 > Project: Apache Freemarker > Issue Type: Improvement > Reporter: Woonsan Ko > Priority: Minor > > FreemarkerServlet doesn't have to set response ContentType by default. > Especially when a controller in an MVC framework sets the response > ContentType, it's better to not set the response ContentType again by the > default ContentType setting in FreemarkerServlet according to servlet > specification (SRV.5.2 and SRV.14.2.22.1): > {quote} > Servlet programmers are responsible for ensuring that the Content-Type header > is appropriately set in the response object for the content the servlet is > generating. The HTTP 1.1 specification does not require that this header be > set in an HTTP response. Servlet containers must not set a default content > type when the servlet programmer does not set the type. > {quote} > {quote} > ServletResponse#getContentType() should "Returns the content type used for > the MIME body sent in this response. The content type proper must have been > specified using setContentType(String) before the response is committed. If > no content type has been specified, this method returns null. If a content > type has been specified and a character encoding has been explicitly or > implicitly specified as described in getCharacterEncoding() , the charset > parameter is included in the string returned. If no character encoding has > been specified, the charset parameter is omitted. > Returns: a String specifying the content type, for example, text/html; > charset=UTF-8, or null > Since: 2.4 > {quote} > So, optionally, if #getContentType() returns null, then FreemarkerServlet can > detect that the Content-Type was never set before. > Actually, frameworks or containers don't have to set Content-Type if > programmers don't. However, I think setting Content-Type header in the > framework level (freemarker servlet in this case) to a reasonable default > value seems fine. > Daniels's remarks/suggestions on this in the old ML: > {quote} > The contentType matter... thanks for looking after these! So then, > FreemarkerServlet surely should set the HttpServletResponse contentType when > it's still null. OTOH there should be an option to only set it then (if it's > not null), not always as it happens now. So then the "ContetType" init-param > remains as is, and we add a new init-param, "OverrideResponseContentType" > (better name?), whose default is true for backward compatibility, but this > default can be changed to false by extending FreemarkerServlet. WDYT? > {quote} -- This message was sent by Atlassian JIRA (v6.3.4#6332)