cfcontent incorrectly appends ;charset=UTF-8 for binary content-types

Description

ie. for image/png types

<cfcontent file="lucee.png" type="image/png">

returns the content type as image/png;charset=UTF-8

HTTP/1.1 200 Content-Type: image/png;charset=UTF-8 Content-Length: 1772 Date: Sat, 01 Aug 2020 15:45:00 GMT

The charset shouldn't be appended, returning a png via cfcontent, should have the same content-type as directly requesting the png file from the webserver

https://github.com/lucee/Lucee/blob/5.3/core/src/main/java/lucee/commons/io/res/ContentTypeImpl.java#L75

Binary mime types have compression disabled
https://github.com/lucee/Lucee/blob/5.3/core/src/main/java/lucee/runtime/tag/Content.java#L180

seems this was a problem with ACF 11 (tho the other problems noted in this don’t occur with Lucee)

https://webdev.cedarville.edu/blog/2015/coldfusion-11-and-charset-encoding-issue-serving-images/

I think charset is only required for text mime types

https://www.w3.org/International/articles/http-charset/index

Environment

None

Attachments

2
  • 01 Aug 2020, 03:48 pm
  • 01 Aug 2020, 03:47 pm

Activity

Show:

Zac Spitzer 29 October 2024 at 11:27

we already have logic for determining if a mime type is text or not

https://github.com/lucee/Lucee/blob/6.2/core/src/main/java/lucee/commons/net/HTTPUtil.java#L659

Michael Offner 8 November 2022 at 14:00

problem is how to know if a mime type is a text mime type or not. we can start doing a list of know mime types and define if they are text or not.

Zac Spitzer 4 February 2021 at 20:20

you can already override the charset using the following syntax, but you can’t remove it

by making it an attribute, this can be set per Application.cfc with this.tags.cfcontent.charset=UTF8;

<cfcontent file="test.png" type="image/png;charset=UTF-8">

Zac Spitzer 4 February 2021 at 19:40

I think three new attributes should be added

  • charset=”false” or custom, UTF-8 etc (currently it comes from the admin setting) default is based on sniffing if it’s a text type

  • compress = true/false/auto (auto being the current default, which sniffs the mime type to see if it’s text)

  • isBinary true/false/auto (default) which is sniffed

Zac Spitzer 4 February 2021 at 18:45

this charset bug also prevents PDFs from downloading with Firefox on android

https://dev.lucee.org/t/cfcontent-type-pdf/7900

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 1 August 2020 at 16:03
Updated 29 October 2024 at 11:27

Flag notifications