freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Dekany (JIRA)" <>
Subject [jira] [Commented] (FREEMARKER-1) Option to not to overwrite response ContentType in FreemarkerServlet
Date Sun, 18 Oct 2015 15:48:05 GMT


Daniel Dekany commented on FREEMARKER-1:

I need to understand your use case better to make a decision. What do you mean be "we don't
have to separate template files then"? I would think that when you write a template, it will
generate output in a single format only. Like HTML only, or JSON only, etc. So don't you already
have a separate template per output format? Also, if you don't set up FreeMarker to use output
formats (which is the case for all pre-2.3.24 applications), the default output format will
be "undefined", which doesn't specify any MIME type, and thus whatever you have set in the
{{HttpServletReponse}} will remain. If, however, you set up FreeMarker to use a more specific
output format for certain templates, or you specify an output format in the {{#ftl}} header,
then why would you want a different MIME type that's specified outside the template?

> Option to not to overwrite response ContentType in FreemarkerServlet
> --------------------------------------------------------------------
>                 Key: FREEMARKER-1
>                 URL:
>             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.
> {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

View raw message