[ 
https://issues.apache.org/jira/browse/FREEMARKER-1?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14962138#comment-14962138
 ] 

Woonsan Ko commented on FREEMARKER-1:
-------------------------------------

Both totally make sense to me! Thanks a lot for caring about the cases I didn't 
think about!

Cheers,

Woonsan

> 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
>            Assignee: Daniel Dekany
>            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)

Reply via email to