[go: up one dir, main page]

Menu

#97 FreemarkerServlet override Content-Type previously set in a Filter

undecided
open
nobody
4
2015-01-02
2013-07-12
No

FreemarkerServlet override Content-Type previously set in a Filter

proposed solution: insert the code below after line 427.
The strategy should be:
1) look if a custom attribute content_type exists
2) if response Content-Type was already set by an external source (e.g. a filter) then leve it alone and use it
3) if default content type miss character encoding add it and use the calculated content type
4) if default content type have character encoding use the default setting

    Object attrContentType = template.getCustomAttribute("content_type");
    if(attrContentType != null) {
        response.setContentType(attrContentType.toString());
    }
    else {
        String ct = response.getContentType();
        if (ct != null) {
            response.setContentType(ct);
        }
        else {
            if (noCharsetInContentType) {
                response.setContentType(
                        contentType + "; charset=" + template.getEncoding());
            } else {
                response.setContentType(contentType);
            }
        }
    }
1 Attachments

Discussion

  • Dániel Dékány

    I guess some other users expect FreeMarker to override the content-type, and certainly at this point many are already relying on that behavior even if they don't realize that. Still this could be an option. However, I'm not sure how to detect if something has already set the content type, or it's just the default of the Servlet container. Is the default always null per Servlet specification?

     
  • Dániel Dékány

    • Group: --> undecided
    • Priority: 5 --> 4
     
  • Dániel Dékány

    Ticket moved from /p/freemarker/bugs/393/

     

Log in to post a comment.